fix(security): validate redirect targets in download functions to prevent SSRF bypass#13111
Merged
fix(security): validate redirect targets in download functions to prevent SSRF bypass#13111
Conversation
…vent SSRF bypass The existing `validateDownloadUrl` only validates the initial URL, but `fetch()` follows redirects by default. An attacker can provide a safe-looking public URL that redirects to internal endpoints like `http://169.254.169.254/latest/meta-data/`, bypassing SSRF protections. Added `response.redirected` check with `validateDownloadUrl(response.url)` in both `downloadBlob` and `download` functions to validate the final URL after following redirects, before reading the response body. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…load tests MSW was not intercepting fetch() calls, causing 2 tests to fail against the real http://example.com. Switched to globalThis.fetch mocking to match the pattern used in download-blob.test.ts. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
vercel-ai-sdk bot
pushed a commit
that referenced
this pull request
Mar 5, 2026
…vent SSRF bypass (#13111) ## Background The existing `validateDownloadUrl` (added in #13085) only validates the initial URL before `fetch()`. Since `fetch()` follows HTTP redirects by default, an attacker can bypass SSRF protections by providing a safe-looking public URL that 302-redirects to internal endpoints (e.g., `http://169.254.169.254/latest/meta-data/`), enabling in-band response body exfiltration through the AI model's response. ## Summary Added `response.redirected` check with `validateDownloadUrl(response.url)` in both `downloadBlob` (`@ai-sdk/provider-utils`) and `download` (`ai`) functions to validate the final URL after following redirects, before reading the response body. ## Manual Verification - `pnpm vitest run packages/provider-utils/src/download-blob.test.ts` — 16 tests pass - `pnpm vitest run packages/provider-utils/src/validate-download-url.test.ts` — 29 tests pass - `pnpm vitest run packages/ai/src/util/download/download.test.ts -t "SSRF"` — 5 tests pass
Contributor
|
✅ Backport PR created: #13127 |
Contributor
|
🚀 Published in:
|
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.
Background
The existing
validateDownloadUrl(added in #13085) only validates the initial URL beforefetch(). Sincefetch()follows HTTP redirects by default, an attacker can bypass SSRF protections by providing a safe-looking public URL that 302-redirects to internal endpoints (e.g.,http://169.254.169.254/latest/meta-data/), enabling in-band response body exfiltration through the AI model's response.Summary
Added
response.redirectedcheck withvalidateDownloadUrl(response.url)in bothdownloadBlob(@ai-sdk/provider-utils) anddownload(ai) functions to validate the final URL after following redirects, before reading the response body.Manual Verification
pnpm vitest run packages/provider-utils/src/download-blob.test.ts— 16 tests passpnpm vitest run packages/provider-utils/src/validate-download-url.test.ts— 29 tests passpnpm vitest run packages/ai/src/util/download/download.test.ts -t "SSRF"— 5 tests passChecklist
pnpm changesetin the project root)Future Work