-
Notifications
You must be signed in to change notification settings - Fork 12.8k
refactor: rewrite checkUrlForSsrf and include it in the server-fetch package
#38044
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
base: develop
Are you sure you want to change the base?
Conversation
|
Looks like this PR is not ready to merge, because of the following issues:
Please fix the issues and try again If you have any trouble, please check the PR guidelines |
🦋 Changeset detectedLatest commit: 3cac769 The changes in this PR will be included in the next version bump. This PR includes changesets to release 41 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| rejectUnauthorized: false, | ||
| }); | ||
| const agentOptions: https.AgentOptions = { | ||
| rejectUnauthorized: false, |
Check failure
Code scanning / CodeQL
Disabling certificate validation High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 17 hours ago
In general, the fix is to stop disabling certificate validation. That means we must avoid rejectUnauthorized: false and instead either (a) use the default HTTPS agent (which validates certificates), or (b) configure a custom agent that still validates certificates but can trust specific non‑standard CAs when needed by providing an explicit CA bundle or similar.
The minimal change that preserves existing functionality while removing the insecure pattern is:
- Do not set
rejectUnauthorized: false. - When
allowSelfSignedCertsisfalse(or unset), keep returningnullso thatnode-fetchuses its default, secure HTTPS agent. - When
allowSelfSignedCertsistrue:- For HTTP, continue to use
new http.Agent()as before. - For HTTPS, replace the custom agent that disables validation with either:
- the default agent (by returning
nullas for the non‑self‑signed case), or - a custom
https.Agentthat still validates certificates (e.g., no special options other than possiblyservername).
- the default agent (by returning
- For HTTP, continue to use
Because originalHostname is used only to set SNI, and SNI can still be set on a validating agent, we can keep that behavior without disabling certificate checks by constructing an https.Agent without overriding rejectUnauthorized. The cleanest change inside getFetchAgent is:
- Remove
rejectUnauthorized: falsefromagentOptions. - Keep
agentOptionsbut make it an empty object initially, and only setservernamewhenoriginalHostnameis provided. - Return a new
https.Agent(agentOptions); this agent will use the defaultrejectUnauthorized: true.
Concretely, within packages/server-fetch/src/index.ts:
- In
getFetchAgent, change theagentOptionsdefinition and remove therejectUnauthorized: falseline. - Leave the function signature and all other logic intact.
No new imports are required; we are only changing the options passed to https.Agent.
-
Copy modified line R37
| @@ -34,9 +34,7 @@ | ||
| return new http.Agent(); | ||
| } | ||
|
|
||
| const agentOptions: https.AgentOptions = { | ||
| rejectUnauthorized: false, | ||
| }; | ||
| const agentOptions: https.AgentOptions = {}; | ||
|
|
||
| if (originalHostname) { | ||
| agentOptions.servername = originalHostname; |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #38044 +/- ##
===========================================
- Coverage 70.65% 70.62% -0.03%
===========================================
Files 3143 3142 -1
Lines 108684 108631 -53
Branches 19571 19551 -20
===========================================
- Hits 76787 76724 -63
- Misses 29893 29906 +13
+ Partials 2004 2001 -3
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
checkUrlForSsrf and include it in the server-fetch packagecheckUrlForSsrf and include it in the server-fetch package
Proposed changes (including videos or screenshots)
Issue(s)
Steps to test or reproduce
Further comments