fix: test failures due to esm.sh rate limits - #5511
Draft
Eugene (OEvgeny) wants to merge 9 commits into
Draft
Conversation
…rough a stack trace Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
| const targetPath = req.url.replace(/^\/esm/u, ''); | ||
| const upstreamUrl = `http://esm:8080${targetPath}`; | ||
|
|
||
| const upstreamRes = await fetch(upstreamUrl); |
Check failure
Code scanning / CodeQL
Server-side request forgery
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 1 year ago
To fix the SSRF vulnerability, we need to restrict the user input (targetPath) to ensure it cannot be used to construct malicious URLs. Specifically:
- Validate
targetPathagainst an allow-list of known safe paths or subpaths. - Ensure that the constructed
upstreamUrlalways points to a trusted domain and does not allow path traversal or injection of unintended query parameters.
The best approach is to introduce an allow-list of valid paths that the user can request. If the targetPath does not match any entry in the allow-list, the request should be rejected with a 400 Bad Request response.
Suggested changeset
1
packages/test/web-server/src/handleESM.ts
| @@ -44,3 +44,4 @@ | ||
| const targetPath = req.url.replace(/^\/esm/u, ''); | ||
| if (!targetPath.startsWith('/')) { | ||
| const allowedPaths = ['/module1', '/module2', '/module3']; // Example allow-list | ||
| if (!allowedPaths.includes(targetPath)) { | ||
| res.writeHead(400); |
Copilot is powered by AI and may make mistakes. Always verify output.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changelog Entry
Description
Design
Specific Changes
-
CHANGELOG.mdReview Checklist
z-index)package.jsonandpackage-lock.jsonreviewed