Repository navigation
fix(security): harden remote media fetching - #2569
Merged
Merged
Conversation
Nikhiljai03
added a commit
to Nikhiljai03/instructor
that referenced
this pull request
Aug 28, 2026
`pdf_to_anthropic` encoded any PDF with unset `data` by calling `requests.get(str(pdf.source))`. That branch is only reachable for non-HTTP sources, because remote `http(s)` URLs return earlier as a URL document block. Every source that could reach it (a local path, `gs://`, `s3://`) is therefore one `requests` cannot resolve, so it raised `MissingSchema`/`InvalidSchema` rather than encoding the document. `PDF.source` is documented as "URL, file path, or base64 data of the PDF", and constructing `PDF(source=Path(...))` directly leaves `data` unset. Building a PDF from a local path and sending it to Anthropic thus always failed, even though the file was readable on disk. Read local files from disk instead, and raise the same clear `ValueError` that `pdf_to_openai` raises when no usable source is present. This also removes the last raw `requests` call left in a provider multimodal module after remote media fetching was centralized in 567-labs#2569. The existing coverage test asserted the broken behaviour by mocking `requests.get`, and additionally failed on Windows because it compared a `Path` against a hardcoded POSIX string. It now writes a real file to `tmp_path`, and two regression tests cover the local-path and missing-source cases.
2 of 3 tasks
3 of 5 tasks
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.
Summary
Security impact
Remote multimodal URLs previously used unrestricted requests calls. An attacker able to influence those URLs could reach internal services or force unbounded response bodies into memory. This change centralizes remote fetching with public-address validation at every redirect, bounded decoded reads, ambient credential/proxy isolation, and explicit peer verification.
Verification