Repository navigation
feat(security): enforce SSRF policy inside Chromium with pinned-DNS egress guard - #91
Merged
Merged
Conversation
…ress proxy Every Chromium connection (navigation, redirects, sub-requests, iframes, websockets) and every request-tier hop now goes through a per-driver / per-call loopback listener. It resolves each destination once through UrlGuard.resolve_host, refuses blocked addresses, and connects to the exact IP it checked, so DNS rebinding cannot swap the address. The user proxy becomes the listener's pinned, authenticated upstream. A refused main-frame navigation maps to the SSRF validation error; refused sub-requests only log egress_blocked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The egress proxy chains to plain-HTTP upstreams only; validate_proxy now returns 400 for other schemes instead of failing at driver/listener construction. Request-tier cleanup no longer leaks the listener if Request() fails. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… per attempt The domain maps the engine's only validation error (egress guard refusing the page's own navigation) to the 403 SSRF contract. The listener's block ledger resets per navigation attempt so an earlier refused sub-request cannot reclassify a later failure. Proxy field docs describe the http:// upstream chaining; openapi.yaml regenerated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Request tier: a proxy 403 response for a refused plain-http redirect hop maps to the SSRF error instead of challenge_block/escalation. - Upstream proxy mode sends the checked IP (CONNECT ip:port, IP authority with original Host), so the upstream cannot re-resolve. - Block 100.64.0.0/10 (CGNAT shared space). - DNS runs on a bounded egress-dns executor with a resolve timeout; client and upstream heads have a read timeout; the block ledger keeps the last 64. - Browser SSRF mapping only counts hosts of the main-frame navigation chain (CDP RequestWillBeSent, loader-id match), never unrelated sub-requests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ledger - XhrCollector reads the top-level frame id (Page.getFrameTree) at install and records navigation hosts only for that frame; iframe Documents also have request id == loader id and no longer 403 the whole scrape. - The block ledger keeps one entry per host (first reason) up to 1024 hosts and never evicts, so repeated or flooding sub-request blocks cannot push out a main-frame hit. - Smoke probe asserts the iframe/sub-request hosts are not main-frame hosts in real Chromium. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gildesmarais
marked this pull request as ready for review
November 30, 2026 13:52
Python's ipaddress flags miss 192.88.99.0/24, 2001:20::/28 and fec0::/10; the gem's NetworkGuard already denies them. metadata.google.internal is now refused by name before resolution. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…crape A hung getaddrinfo keeps its thread after the timeout, so one page could fill the shared DNS pool and stall every concurrent scrape. Each listener now holds at most 4 lookups, released only when the thread returns, on a 32-worker pool. A checked answer is reused for the listener's lifetime and concurrent connections share one lookup; refusals are not kept, so each attempt still records its blocks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 30, 2026
Merged
The destination still passes the local resolve-and-check, but the upstream now gets host:port instead of the pinned IP. It resolves on its own network, which cannot reach ours, and TLS-inspecting or geo-routed upstreams (residential gateways) need the name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
--force-webrtc-ip-handling-policy is ignored by the bundled Chromium: pages still gathered srflx candidates, sending UDP to page-chosen STUN addresses (including private ones) around the egress proxy and exposing the host IP next to an upstream proxy. Each profile is now seeded with webrtc.ip_handling_policy=disable_non_proxied_udp before launch, so WebRTC gathers no candidates. Smoke asserts it in Chromium. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…idate ICE connectivity checks to a candidate passed via addIceCandidate are a second UDP path around the egress proxy. Without the seeded preference Chromium sent 129 packets to such an address; the probe now requires 0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
egress_blocked now carries request_id/host (the listener logs from its own threads, which never saw the request context; warm spares re-attach on adoption) and is logged once per host per attempt instead of per connection. Each listener emits one egress_summary on close when anything was refused or failed: blocked connections, DNS timeouts/failures, connect failures and upstream proxy refusals with their status (WARNING when the upstream refused or DNS timed out). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 30, 2026
gildesmarais
added a commit
to html2rss/html2rss
that referenced
this pull request
Nov 30, 2026
…anchors (#723) ## What changed - `request.botasaurus.proxy` must now start with `http://`, and credentials are still allowed. `https://` and `socks` URLs fail config validation with `is in invalid format`. - The rule lives in `BotasaurusContract::PROXY_FORMAT`. - `Config::Validator` applies it. - `Config::Schema::Builder` now maps Ruby's whole-string anchors `\A`/`\z` to ECMA-262 `^`/`$` in every exported `pattern`. Example and default values are left untouched. - JSON Schema validators read `pattern` as ECMA-262, which has neither anchor. Until now `channel.language` (`\A…\z`) rejected every valid value in schema-aware editors. - Ruby validators keep the strict anchors. - `schema/html2rss-config.schema.json` is regenerated: `channel.language` and `request.botasaurus.proxy` now export `^…$` and `^http:\/\/`. - `spec/fixtures/botasaurus/openapi.yaml` is vendored from the scrape API with the new `proxy` description. ## Why html2rss/botasaurus-scrape-api#91 sends all scrape traffic through an egress guard. The request `proxy` becomes that guard's upstream, and the guard talks only plain HTTP to it. Without this change, an `https://` or `socks` proxy in a feed config would pass validation here and then fail at scrape time with a 400 from the API. Rejecting it at config load points the failure at the config. ## Risk - Existing configs with a `socks` or `https://` proxy stop validating. With #91 deployed they could not scrape anyway. - Merge after html2rss/botasaurus-scrape-api#91. The sibling-OpenAPI sync spec expects that PR's `openapi.yaml`. Review map: small. Start at `spec/lib/html2rss/config/validator_spec.rb`, then `spec/lib/html2rss/config/schema_spec.rb`. ## Validation - `make ready`: 8717 examples and 0 failures, RuboCop clean, the schema check passes. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
gildesmarais
added a commit
to html2rss/html2rss
that referenced
this pull request
Nov 30, 2026
## What changed - `request.botasaurus.timezone`, an IANA id such as `Europe/Berlin`, is a new accepted option. It is forwarded on `POST /scrape` through `BotasaurusContract::REQUEST_OPTION_KEYS`. `Config::Validator` accepts it as a non-empty string. - `spec/fixtures/botasaurus/openapi.yaml` is vendored from html2rss/botasaurus-scrape-api#92. `schema/html2rss-config.schema.json` is regenerated. - The six boolean Botasaurus options are declared in one loop, so the schema block stays within `Metrics/BlockLength`. The exported schema is unchanged by this. ## Why The scrape API now lets the caller set the timezone the browser reports to pages, for example to match a residential proxy's exit country (#92). Without the key here, feed configs could not set it. ## Risk - Low. The scrape API owns the IANA check and answers unknown ids with `422`, so the gem does not duplicate the tz database. - Merge order: 1. html2rss/botasaurus-scrape-api#91, then #92 2. #723 3. this PR, retargeted to `master` Review map: small. Start at `spec/lib/html2rss/request_service/botasaurus_contract_spec.rb`. ## Validation - `make ready`: 8717 examples and 0 failures, RuboCop clean, the schema check passes. The sibling-OpenAPI sync spec ran against #92's `openapi.yaml`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <noreply@anthropic.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.
What changed
app/security/egress_proxy.py.--proxy-serverpointing at that listener--proxy-bypass-list=<-loopback>--disable-quicdisable_non_proxied_udpbefore launch. The matching--force-webrtc-ip-handling-policyflag is ignored by the bundled Chromium: pages still gatheredsrflxcandidates, sending UDP to page-chosen STUN addresses (private ones included) around the proxy and exposing the host IP. With the preference, WebRTC gathers no candidates.UrlGuard.resolve_hostis now the only place the rule lives.validate()and the listener both call it.is_blocked_ipchanges:100.64.0.0/10(CGNAT),192.88.99.0/24,2001:20::/28andfec0::/10are now blocked. The stdlib flags miss them; the gem already denies them.metadata.google.internalis refused by name, likelocalhost.403witherror_category=validation(ScrapeService).egress_blocked, and the page still succeeds.egress_blockedcarries the scrape'srequest_idandhost. It is logged once per host per attempt, and repeats are only counted.egress_summaryon close when anything was refused or failed. It counts blocked connections, DNS timeouts and failures, connect failures and upstream proxy refusals, and records the upstream's status (for example407or402). It logs atWARNINGwhen the upstream refused or DNS timed out.frame_id, compared with the top-level frame (XhrCollector).proxymust behttp://. It becomes the listener's next hop. Each destination is still resolved and checked locally first. The upstream then receives the hostname (CONNECT host:port), because it resolves on its own network, which cannot reach ours. TLS-inspecting and geo-routed upstreams, such as residential gateways, need the name.Why
Before this change, only the top-level URL was checked, once, before the scrape. After that, Chromium resolved and fetched whatever the page asked for. That included redirects and sub-requests to private, link-local and metadata addresses. A hostname could also resolve to a public address at check time and a private one at connect time.
With a fixed proxy, Chromium resolves no names itself. The guard resolves, checks, and connects by IP, so rebinding has nothing to race.
Filtering egress at the host level was rejected: it needs host firewall rules that are not kept in git.
Risk
getaddrinfoplus a loopback hop. Request-mode bench p50 was 62.5 ms before and 50.6–74.4 ms after. Network noise is larger than any difference. Browser-mode p50 (8 runs, Docker) before → after: Wikipedia article 11.7 s → 11.7 s, Guardian front page 12.1 s → 9.6 s, which is within noise.https://andsocksupstream proxies now get a 400. Onlyhttp://is supported.getaddrinfocall that hangs keeps its DNS worker until the resolver gives up. It counts against that listener's 4 slots, so other scrapes keep resolving.ScrapeServicepicks 403 fromerror_category == validation, not from a typed signal. Today only the egress block emits that category.XhrCollector._on_responsestill matches the main document by request id == loader id. An iframe document response can therefore overwrite the status and headers it captured.Review map
tests/security/test_egress_proxy.py: rebinding refused, IP pinning, blocked classes over CONNECT and plain HTTP, upstream hostname forwarding and auth, timeouts, ledger dedupe.tests/engine/test_egress_tiers.py: request-tier redirect and 403-response paths, browser main-frame block, sub-request and iframe not escalated, per-attempt reset.tests/api/test_http_contract.py: blocked navigation returns403.app/security/egress_proxy.py: the listener, the event loop, the resolver pool.app/security/url_guard.py:resolve_hostas the single owner of the policy.app/engine/browser_tier.py,app/engine/request_tier.py,app/engine/warm_pool.py: how each tier is wired to the listener.app/infra/xhr_collector.py: capture of the main-frame navigation chain.scripts/smoke.sh: an in-Chromium egress probe against real CDP.Validation
make check: 251 tests, pyright 0 errors, openapi-verify ok.make smoke: bothcontract-prewarm-offandprewarm-on-warm-handoffpass, including the new egress probe. It checks that an img to 169.254.169.254 and an iframe to 10.0.0.1 are blocked while the page renders, and that a main-frame navigation to 127.0.0.1 is refused and recorded. It also checks that WebRTC gathers no ICE candidates, given STUN servers at 10.0.0.1 and a public host. Without the seeded preference, the same check returned a host and asrflxcandidate. A second check hands Chromium a remote candidate on a local UDP port and requires 0 packets to arrive. Without the preference, 129 arrived.Follow-ups (merge after this)
http://proxies at config validation and vendors thisopenapi.yaml.proxyoption.🤖 Generated with Claude Code