-
Notifications
You must be signed in to change notification settings - Fork 12
fix: Sanitize URL in prepare-package-lock script #71
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
Conversation
| } 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
Show autofix suggestion
Hide autofix suggestion
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:
- Parsing the
dependency.resolvedURL using theURLconstructor. - Checking if the host matches
codeartifact.us-west-2.amazonaws.comor ends with.codeartifact.us-west-2.amazonaws.comwhile ensuring it is a valid subdomain.
-
Copy modified lines R28-R32
| @@ -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"); | ||
| })() | ||
| ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in latest commit
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
CONTRIBUTING.md.CONTRIBUTING.md.Security
checkSafeUrlfunction.Testing
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.