fix(security): add URL validation to prevent SSRF in download functions#13085
Merged
fix(security): add URL validation to prevent SSRF in download functions#13085
Conversation
Add validateDownloadUrl utility that blocks private/internal addresses, non-HTTP protocols, and localhost before fetching user-provided URLs in downloadBlob and download functions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
|
|
Contributor
|
🚀 Published in:
|
4 tasks
gr2m
added 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
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
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
downloadBlobfunction (@ai-sdk/provider-utils) anddownloadfunction (ai) fetch user-provided URLs without any validation. When users pass image URLs togenerateImage(), strings starting with "http" flow directly tofetch()viadownloadBlob(file.url)in OpenAI, OpenAI-compatible, and DeepInfra image models. This enables blind SSRF — attackers can make the server request internal resources (localhost, cloud metadata endpoints like169.254.169.254, private IPs).Summary
Added a shared
validateDownloadUrlutility in@ai-sdk/provider-utilsthat bothdownloadBlobanddownloadcall beforefetch. It throwsDownloadErrorif the URL is unsafe:http:andhttps:allowedlocalhost,*.local,*.localhost, empty hostname127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,169.254.0.0/16,0.0.0.0/8::1,fc00::/7,fe80::/10,::, and IPv4-mapped addresses (::ffff:x.x.x.x)No DNS resolution checks (not available in edge runtimes). Reuses
DownloadErrorfor rejected URLs.Manual Verification
pnpm vitest run src/validate-download-url.test.tsinpackages/provider-utils— 29 tests passpnpm vitest run src/download-blob.test.tsinpackages/provider-utils— 13 tests passpnpm vitest run src/util/download/download.test.tsinpackages/ai— 7 tests passChecklist
pnpm changesetin the project root)Future Work