-
Notifications
You must be signed in to change notification settings - Fork 59
fix(net): prevent SSRF bypass via redirect in safeFetch #486
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: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -99,4 +99,12 @@ describe('safeFetch', () => { | |||||
|
|
||||||
| await expect(safeFetch('https://cdn.example.com/missing.png')).rejects.toThrow('404'); | ||||||
| }); | ||||||
|
|
||||||
| it('passes redirect:error to net.fetch to prevent SSRF bypass via 3xx', async () => { | ||||||
| assertNotPrivateHostMock.mockResolvedValue(undefined); | ||||||
| netFetchMock.mockResolvedValue(mockResponse(new ArrayBuffer(4))); | ||||||
|
|
||||||
| await safeFetch('https://cdn.example.com/img.png'); | ||||||
| expect(netFetchMock).toHaveBeenCalledWith(expect.any(String), expect.objectContaining({ redirect: 'error' })); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of using
Suggested change
|
||||||
| }); | ||||||
| }); | ||||||
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.
To prevent potential SSRF bypasses via URL parser differentials, it is safer to use the normalized URL from the
parsedobject rather than the originalurlstring. This ensures that the URL fetched bynet.fetchis exactly the same one that was validated by the protocol and hostname checks. This is a recommended security practice when implementing SSRF guards to avoid discrepancies between how different libraries parse the same URL string.References