Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge keyring version #322

Merged
merged 769 commits into from
Feb 19, 2025
Merged

Merge keyring version #322

merged 769 commits into from
Feb 19, 2025

Conversation

toandq2009
Copy link
Collaborator

No description provided.

throw new Error("origin unmatched");
}

window.location.replace(origin);

Check warning

Code scanning / CodeQL

Client-side URL redirect Medium

Untrusted URL redirection depends on a
user-provided value
.

Copilot Autofix AI 3 days ago

To fix the problem, we need to ensure that the origin parameter is validated against a list of authorized URLs before performing the redirect. This can be achieved by maintaining a list of trusted URLs and checking if the origin parameter matches any of these URLs. If it does not match, the redirect should not be performed.

  1. Create a list of authorized URLs.
  2. Check if the origin parameter is in the list of authorized URLs before performing the redirect.
  3. If the origin parameter is not in the list, do not perform the redirect and show an appropriate error message.
Suggested changeset 1
apps/extension/src/pages/blocklist/index.tsx

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/apps/extension/src/pages/blocklist/index.tsx b/apps/extension/src/pages/blocklist/index.tsx
--- a/apps/extension/src/pages/blocklist/index.tsx
+++ b/apps/extension/src/pages/blocklist/index.tsx
@@ -76,2 +76,8 @@
 
+const authorizedUrls = [
+  "https://trusted-site1.com",
+  "https://trusted-site2.com",
+  // Add more trusted URLs here
+];
+
 export const BlocklistPage: FunctionComponent = () => {
@@ -89,5 +95,4 @@
         // Validate url
-        const url = new URL(origin);
-        if (redirectUrl.origin !== url.origin) {
-          throw new Error("origin unmatched");
+        if (!authorizedUrls.includes(origin)) {
+          throw new Error("Unauthorized origin");
         }
EOF
@@ -76,2 +76,8 @@

const authorizedUrls = [
"https://trusted-site1.com",
"https://trusted-site2.com",
// Add more trusted URLs here
];

export const BlocklistPage: FunctionComponent = () => {
@@ -89,5 +95,4 @@
// Validate url
const url = new URL(origin);
if (redirectUrl.origin !== url.origin) {
throw new Error("origin unmatched");
if (!authorizedUrls.includes(origin)) {
throw new Error("Unauthorized origin");
}
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
throw new Error("origin unmatched");
}

window.location.replace(origin);

Check failure

Code scanning / CodeQL

Client-side cross-site scripting High

Cross-site scripting vulnerability due to
user-provided value
.

Copilot Autofix AI 3 days ago

To fix the problem, we need to ensure that the origin value is properly sanitized before it is used in the URL redirection. One way to achieve this is by using a library like DOMPurify to sanitize the origin value. This will help prevent any malicious scripts from being executed.

  1. Install the DOMPurify library.
  2. Import DOMPurify in the file.
  3. Use DOMPurify to sanitize the origin value before using it in the URL redirection.
Suggested changeset 2
apps/extension/src/pages/blocklist/index.tsx

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/apps/extension/src/pages/blocklist/index.tsx b/apps/extension/src/pages/blocklist/index.tsx
--- a/apps/extension/src/pages/blocklist/index.tsx
+++ b/apps/extension/src/pages/blocklist/index.tsx
@@ -6,2 +6,3 @@
 import { AppThemeProvider } from "../../theme";
+import DOMPurify from "dompurify";
 
@@ -78,3 +79,3 @@
   const origin =
-    new URLSearchParams(window.location.search).get("origin") || "";
+    DOMPurify.sanitize(new URLSearchParams(window.location.search).get("origin") || "");
 
EOF
@@ -6,2 +6,3 @@
import { AppThemeProvider } from "../../theme";
import DOMPurify from "dompurify";

@@ -78,3 +79,3 @@
const origin =
new URLSearchParams(window.location.search).get("origin") || "";
DOMPurify.sanitize(new URLSearchParams(window.location.search).get("origin") || "");

apps/extension/package.json
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/apps/extension/package.json b/apps/extension/package.json
--- a/apps/extension/package.json
+++ b/apps/extension/package.json
@@ -103,3 +103,4 @@
     "web3-utils": "4.11.1",
-    "webextension-polyfill": "^0.10.0"
+    "webextension-polyfill": "^0.10.0",
+    "dompurify": "^3.2.4"
   },
EOF
@@ -103,3 +103,4 @@
"web3-utils": "4.11.1",
"webextension-polyfill": "^0.10.0"
"webextension-polyfill": "^0.10.0",
"dompurify": "^3.2.4"
},
This fix introduces these dependencies
Package Version Security advisories
dompurify (npm) 3.2.4 None
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options

const isNeg = res.startsWith("-");
return {
text: isNeg ? res.replace("-", "-") : "+" + res,

Check warning

Code scanning / CodeQL

Replacement of a substring with itself Medium

This replaces '-' with itself.

Copilot Autofix AI 3 days ago

To fix the problem, we need to replace the substring "-" with the correct transformation. The intention seems to be to format the string res to include a "+" sign for positive values and retain the "-" sign for negative values. Therefore, we should ensure that the "+" sign is added correctly for positive values and the "-" sign is retained for negative values without unnecessary replacement.

  • Identify the line with the problematic replacement: res.replace("-", "-").
  • Replace this line with a conditional check to prepend a "+" sign for positive values and retain the "-" sign for negative values without using the replace method.
Suggested changeset 1
apps/extension/src/pages/main/components/token/index.tsx

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/apps/extension/src/pages/main/components/token/index.tsx b/apps/extension/src/pages/main/components/token/index.tsx
--- a/apps/extension/src/pages/main/components/token/index.tsx
+++ b/apps/extension/src/pages/main/components/token/index.tsx
@@ -990,3 +990,3 @@
       return {
-        text: isNeg ? res.replace("-", "-") : "+" + res,
+        text: isNeg ? res : "+" + res,
         isNeg,
EOF
@@ -990,3 +990,3 @@
return {
text: isNeg ? res.replace("-", "-") : "+" + res,
text: isNeg ? res : "+" + res,
isNeg,
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
"Content-Type": "application/json",
},
body: JSON.stringify({
transactions: transactions,

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data High

This
regular expression
that depends on
library input
may run slow on strings starting with '(' and with many repetitions of '('.
Comment on lines +27 to +28
const split = chainId
.split(ChainIdHelper.VersionFormatRegExp)

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data High

This
regular expression
that depends on
library input
may run slow on strings with many repetitions of 'a'.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of 'a'.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of 'a'.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of 'a'.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of 'a'.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of 'a'.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of 'a'.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of 'a'.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of 'a'.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of 'a'.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of 'a'.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of 'a'.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of 'a'.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of 'a'.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of 'a'.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of 'a'.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of 'a'.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of 'a'.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of 'a'.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of 'a'.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of 'a'.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of 'a'.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of 'a'.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of 'a'.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of 'a'.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of 'a'.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of 'a'.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of 'a'.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of 'a'.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of 'a'.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of 'a'.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of 'a'.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of 'a'.
This
regular expression
that depends on
library input
may run slow on strings with many repetitions of 'a'.
This
regular expression
that depends on [library inpu
Comment on lines +349 to +351
const isChecksumAddress = !!hexAddress.match(
/([A-F].*[a-f])|([a-f].*[A-F])/
);

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data High

This
regular expression
that depends on
library input
may run slow on strings starting with 'A' and with many repetitions of 'A'.
This
regular expression
that depends on
library input
may run slow on strings starting with 'a' and with many repetitions of 'a'.
This
regular expression
that depends on
library input
may run slow on strings starting with 'A' and with many repetitions of 'A'.
This
regular expression
that depends on
library input
may run slow on strings starting with 'a' and with many repetitions of 'a'.
This
regular expression
that depends on
library input
may run slow on strings starting with 'A' and with many repetitions of 'A'.
This
regular expression
that depends on
library input
may run slow on strings starting with 'a' and with many repetitions of 'a'.
toandq2009 and others added 4 commits February 19, 2025 11:23
…ing or encoding

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@toandq2009 toandq2009 merged commit c93c34b into main Feb 19, 2025
3 of 4 checks passed
@toandq2009 toandq2009 deleted the feat/merge-all branch February 19, 2025 04:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants