fix: skip data: URLs in downloadAssets to prevent SSRF false positive#13204
Open
MaxwellCalkin wants to merge 1 commit intovercel:mainfrom
Open
fix: skip data: URLs in downloadAssets to prevent SSRF false positive#13204MaxwellCalkin wants to merge 1 commit intovercel:mainfrom
MaxwellCalkin wants to merge 1 commit intovercel:mainfrom
Conversation
data: URLs contain inline base64 content and should not be passed to the download function. The SSRF protection in validateDownloadUrl() correctly rejects non-http(s) protocols, but data: URLs are not remote resources — they are inline data that is already handled downstream by convertToLanguageModelV4DataContent(). Filter out data: URLs from planned downloads so they flow through to the existing base64 extraction path instead of hitting the download validation.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
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.
Note: This PR was authored by Claude (AI), operated by @MaxwellCalkin.
Fixes #13103
Problem
The SSRF protection added in
@ai-sdk/provider-utils@4.0.19rejectsdata:URLs during thedownloadAssetsphase, breaking inline file attachments (images, PDFs) sent as base64 data URLs.In
downloadAssets(), string data from file/image parts is converted toURLobjects vianew URL(data). Sincedata:image/png;base64,...is a valid URL, it becomes aURLinstance and passes theinstanceof URLfilter. The default download function then callsvalidateDownloadUrl(), which correctly rejects non-http(s)protocols — butdata:URLs are inline data, not remote resources.Fix
Filter out
data:URLs from planned downloads indownloadAssets()by adding&& part.data.protocol !== "data:"to the existinginstanceof URLcheck. This letsdata:URLs bypass the download pipeline entirely and flow through toconvertToLanguageModelV4DataContent(), which already handles them correctly by extracting the base64 content.Changed files
packages/ai/src/prompt/convert-to-language-model-prompt.ts: Addedpart.data.protocol !== "data:"to the URL filter indownloadAssets()packages/ai/src/prompt/convert-to-language-model-prompt.test.ts: Added two tests verifyingdata:URLs are not passed to the download function (one for image parts, one for file parts)Before
After
data:URLs are correctly skipped during download planning and their inline base64 content is extracted by the existingconvertToLanguageModelV4DataContent()path.