Repository navigation
fix(security): block SSRF and bound extract_url fetches - #18
Merged
Merged
Conversation
Remove dependencies nothing uses: async-trait, futures, regex, unicode-segmentation, encoding_rs, base64, mime, lol_html and tracing-subscriber from core and the workspace, plus unused deps of the CLI, bindings and the stub bench/eval crates. The stub bench deps were the only source of the instant/paste unmaintained advisories, so their deny.toml ignores go too. Upgrade scraper 0.29, html5ever 0.40, pyo3 0.30, criterion 0.8 and quick-xml 0.42, which unifies with calamine's copy; port the XML walkers to its str-based names and values.
extract_url refuses non-public destinations by default (URL check, redirect policy, DNS resolver filter), allows only http/https, caps redirects, bounds the body by max_input_size while streaming and the fetch by max_processing_secs. New builder options allow_private_networks, allow_host, max_redirects and Error::UrlBlocked. Threat model T3 mitigated, invariant S12.
The ptrace engine segfaults on the multi-threaded tokio socket tests in tests/url_security.rs.
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.
What changed
extract_url(and so the CLI, Pythonextract_urland NodeextractUrl) now treats the URL as untrusted:Error::UrlBlocked. That covers loopback, RFC 1918, link-local / cloud metadata (169.254.169.254), CGNAT, reserved and multicast ranges, the IPv6 equivalents, and IPv4 embedded in IPv6 (mapped, NAT64, 6to4). The check runs at three layers:http/httpsare fetched.max_redirects(default 5).max_input_size. A declaredContent-Lengthover the limit is rejected up front; a body without one is stopped while streaming. Before this change the whole body was buffered first.max_processing_secs. Before this change there was no timeout.allow_private_networks(true)for trusted internal URLs, andallow_host(..)for an exact, case-insensitive host allowlist that is checked on every hop.Why
Threat model T3 (SSRF) was open. With the default
http_clientfeature, anyone passing an attacker-chosen URL could reach internal services or cloud metadata, or exhaust memory and time.Before / After
Before:
markkit extract http://169.254.169.254/latest/meta-data/sent the request, and no limits applied to the body or the time taken.After:
The new
tests/url_security.rshas 14 tests, run against a local raw-TCP server. Before the fix, 9 of them failed. Now all 14 pass, as do 5 new unit tests infetch::tests.just pre-pris green.Risk
allow_private_networks(true). The CLI and the bindings have no opt-in flag yet.HTTP(S)_PROXYis set in the environment, the proxy resolves names itself, so the resolver filter can't apply. The URL, allowlist and redirect checks still do. This is documented in T3 and SECURITY.md.Checklist
Errorvariant)Generated by Claude Code