Repository navigation
[critical] fix: [html_to_markdown] block unspecified, shared, ULA and link-local ranges in the URL safety check - #908
Open
elhoim wants to merge 1 commit into
Conversation
… ranges is_safe_url() still let http://0.0.0.0/ (reaches loopback on Linux), 100.64.0.0/10 (carrier-grade NAT), [::], fc00::/7 and fe80::/10 through, because BLOCKED_RANGES only listed loopback, RFC 1918 and IPv4 link-local. Add those ranges, including their IPv4-mapped forms via the existing normalisation, and cover them with literal and resolved-host tests. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This branch has not been deployed
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.
BLUF
is_safe_url()still acceptshttp://0.0.0.0/(reaches loopback on Linux),100.64.0.0/10,[::],fc00::/7(ULA) andfe80::/10(IPv6 link-local), becauseBLOCKED_RANGESlists only loopback, RFC 1918 and IPv4 link-local.BLOCKED_RANGES. IPv4-mapped forms such as[::ffff:0.0.0.0]are covered through the existing normalisation.fetchHTMLand the redirect handling are unchanged.Supersedes #848.
Background
#848 fixed two problems: unchecked redirects and the missing address ranges. Upstream has since fixed the redirect half in f359a02 ("prevent HTML URL parser SSRF bypass") and 2448f74 ("preserve session state across safe redirects"). This PR is rebuilt on current
mainand carries only the part that is still open.#848 replaced the list with
not ip.is_global. That is not reused here, because192.0.2.0/24is notis_globaleither, and the existing tests use192.0.2.1as the allowed address. Extending the explicit list keeps those tests and the current structure as they are.Verification
python -m unittest -v tests.test_html_to_markdown: 12 tests pass, including the two new ones (asubTestloop over literal URLs, and a hostname that resolves tofd00::1).markdownifyis not installed on the test host, so it was replaced with an import stub. These tests never call it.flake8with the[tool.flake8]settings frompyproject.toml: clean.pytestsuite andblackwere not run locally.