Skip to content
Merged
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion scripts/prepare-package-lock.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@

if (dependencyName.includes("@cloudscape-design/")) {
delete packages[dependencyName];
} 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

'[codeartifact.us-west-2.amazonaws.com](1)' may be preceded by an arbitrary host name.

Copilot Autofix

AI 6 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

) {
throw Error(
"package-lock.json file contains a reference to CodeArtifact. Use regular npm to update the packages.",
);
Expand Down
Loading