Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion app/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,36 @@
}
}

// attempt 6: chromium 000005.ldb on windows
// attemp 6: When the backup file is not a valid json, it tries to extract the keyring controller object from the string.
{
const matches = data.match(
/(?<="KeyringController":)(.*?)(?=,"[a-zA-z]+":{)/

Check warning

Code scanning / CodeQL

Overly permissive regular expression range Medium

Suspicious character range that overlaps with a-z in the same character class, and is equivalent to [A-Z[]^_`a-z].

Copilot Autofix

AI 11 months ago

To fix the problem, we need to correct the overly permissive regular expression range by specifying the correct ranges for uppercase and lowercase letters separately. This ensures that only the intended characters are matched.

  • Replace the range A-z with A-Za-z to match only uppercase and lowercase alphabetical characters.
  • Update the regular expression on line 122 to use the corrected range.
Suggested changeset 1
app/lib.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/app/lib.js b/app/lib.js
--- a/app/lib.js
+++ b/app/lib.js
@@ -121,3 +121,3 @@
     const matches = data.match(
-      /(?<="KeyringController":)(.*?)(?=,"[a-zA-z]+":{)/
+      /(?<="KeyringController":)(.*?)(?=,"[a-zA-Za-z]+":{)/
     );
EOF
@@ -121,3 +121,3 @@
const matches = data.match(
/(?<="KeyringController":)(.*?)(?=,"[a-zA-z]+":{)/
/(?<="KeyringController":)(.*?)(?=,"[a-zA-Za-z]+":{)/
);
Copilot is powered by AI and may make mistakes. Always verify output.
);
if (matches && matches.length) {
try {
const keyringControllerStateFragment = matches[1];
const dataRegex = /\\"data\\":\\"([A-Za-z0-9+\/]*=*)/u;
const ivRegex = /,\\"iv\\":\\"([A-Za-z0-9+\/]{10,40}=*)/u;
const saltRegex = /,\\"salt\\":\\"([A-Za-z0-9+\/]{10,100}=*)\\"/;
const keyMetaRegex = /,\\"keyMetadata\\":(.*}})/;

const vaultParts = [dataRegex, ivRegex, saltRegex, keyMetaRegex]
.map((reg) => keyringControllerStateFragment.match(reg))
.map((match) => match[1]);

return {
data: vaultParts[0],
iv: vaultParts[1],
salt: vaultParts[2],
keyMetadata: JSON.parse(vaultParts[3].replaceAll("\\", "")),
};
} catch (err) {
// Not valid JSON: continue
}
}
}

// attempt 7: chromium 000005.ldb on windows
const matchRegex = /Keyring[0-9][^\}]*(\{[^\{\}]*\\"\})/gu
const captureRegex = /Keyring[0-9][^\}]*(\{[^\{\}]*\\"\})/u
const ivRegex = /\\"iv.{1,4}[^A-Za-z0-9+\/]{1,10}([A-Za-z0-9+\/]{10,40}=*)/u
Expand Down
Loading