Skip to content

fix(security): harden remote media fetching - #2569

Merged
jxnl-oai merged 1 commit into
567-labs:mainfrom
jxnl-oai:fix/security-media-fetching
Aug 28, 2026
Merged

jxnl-oai merged 1 commit into
567-labs:mainfrom
jxnl-oai:fix/security-media-fetching

Conversation

@jxnl-oai

Copy link
Copy Markdown
Collaborator

Summary

  • block SSRF through loopback, private, link-local, multicast, credential-bearing, and unsafe redirect targets
  • verify the connected peer to defend against DNS rebinding and fail closed when it cannot be inspected
  • stream and cap remote image, audio, and PDF downloads; stop caching media payloads in process memory
  • refresh vulnerable runtime dependency floors and generated locks while preserving Python 3.9 compatibility
  • pin GitHub Actions to reviewed commit SHAs and add Dependabot coverage/cooldowns

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

  • 165 focused multimodal, provider, and security tests passed; 1 skipped
  • 26 remote-fetch security tests passed on Python 3.9
  • Ruff check and format checks passed
  • ty checks passed for source and tests
  • pip-audit reports no known vulnerabilities in the generated current-Python requirements
  • uv lock validation and package build passed

@jxnl-oai
jxnl-oai merged commit 000d893 into 567-labs:main Aug 28, 2026
24 checks passed
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant