Skip to content

Conversation

jperals
Copy link
Member

@jperals jperals commented Jul 25, 2025

Description

This makes sure that the check does not give false positives (for example, by the string being found in URL parameters).

Related links, issue #, if available: Code Scanning alert #5

How has this been tested?

Review checklist

The following items are to be evaluated by the author(s) and the reviewer(s).

Correctness

  • Changes include appropriate documentation updates.
  • Changes are backward-compatible if not indicated, see CONTRIBUTING.md.
  • Changes do not include unsupported browser features, see CONTRIBUTING.md.
  • Changes were manually tested for accessibility, see accessibility guidelines.

Security

Testing

  • Changes are covered with new/existing unit tests?
  • Changes are covered with new/existing integration tests?

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

} else if (dependency.resolved && dependency.resolved.includes("codeartifact.us-west-2.amazonaws.com")) {
} else if (
dependency.resolved &&
new URL(dependency.resolved).host.endsWith("codeartifact.us-west-2.amazonaws.com")

Check failure

Code scanning / CodeQL

Incomplete URL substring sanitization High

'codeartifact.us-west-2.amazonaws.com' may be preceded by an arbitrary host name.

Copilot Autofix

AI 2 months ago

To fix the issue, we need to ensure that the host is explicitly validated as either the exact domain codeartifact.us-west-2.amazonaws.com or one of its subdomains. This can be achieved by parsing the URL and checking the host against a whitelist of allowed domains. Specifically, we should verify that the host is either codeartifact.us-west-2.amazonaws.com or ends with .codeartifact.us-west-2.amazonaws.com but is not preceded by an arbitrary string.

The fix involves:

  1. Parsing the dependency.resolved URL using the URL constructor.
  2. Checking if the host matches codeartifact.us-west-2.amazonaws.com or ends with .codeartifact.us-west-2.amazonaws.com while ensuring it is a valid subdomain.

Suggested changeset 1
scripts/prepare-package-lock.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/scripts/prepare-package-lock.js b/scripts/prepare-package-lock.js
--- a/scripts/prepare-package-lock.js
+++ b/scripts/prepare-package-lock.js
@@ -27,3 +27,7 @@
       dependency.resolved &&
-      new URL(dependency.resolved).host.endsWith("codeartifact.us-west-2.amazonaws.com")
+      (() => {
+        const host = new URL(dependency.resolved).host;
+        return host === "codeartifact.us-west-2.amazonaws.com" || 
+               host.endsWith(".codeartifact.us-west-2.amazonaws.com");
+      })()
     ) {
EOF
@@ -27,3 +27,7 @@
dependency.resolved &&
new URL(dependency.resolved).host.endsWith("codeartifact.us-west-2.amazonaws.com")
(() => {
const host = new URL(dependency.resolved).host;
return host === "codeartifact.us-west-2.amazonaws.com" ||
host.endsWith(".codeartifact.us-west-2.amazonaws.com");
})()
) {
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in latest commit

@jperals jperals marked this pull request as ready for review July 25, 2025 09:03
@jperals jperals requested a review from pan-kot as a code owner July 25, 2025 09:04
@jperals jperals added this pull request to the merge queue Aug 4, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Aug 4, 2025
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.

2 participants