Repository navigation
Conversation
Follow InputFile URL redirects manually and resolve/validate each hop before connecting so a public host cannot bounce the hosted server onto loopback, private, or link-local addresses. Pin TCP to the validated IP while keeping Host and TLS SNI on the original hostname. Return a generic fetch error to callers so redirect failures are not an SSRF oracle. Co-authored-by: Jake Barnby <abnegate@users.noreply.github.com>
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.
Problem
Hosted InputFile URL fetches (
_fetch_input_file) validated the caller-supplied URL, then let httpx follow redirects automatically and only re-checkedresp.urlafter the final request had already been sent. A public host that answered302 Location: http://169.254.169.254/...(or loopback / RFC1918) made the server issue a GET to that internal address. The post-fetch check discarded the body, but the request had already happened.Fetch failures were also an oracle: a blocked internal hop, an HTTP error, and a connection failure each produced different caller-visible text, and httpx errors included the final URL and status code.
Fix
Locationmanually up to the existingFETCH_MAX_REDIRECTScap.Location, including relative ones viaurljoin) before opening a connection to that hop.Hostand TLSsni_hostname, so HTTPS certificate verification is unchanged and the resolve-then-reconnect DNS-rebinding window is closed.Tests
Unit coverage in
tests/unit/test_server.py:Locationis joined against the logical hostname, not the pinned IPgetaddrinfois mocked; tests do not use the public internetChecks
ruff,black --check,pyright, andpython -m unittest discover -s tests/unitpass locally.