Skip to content

Check every request hop in the outbound URL guard - #17146

Open
svader0 wants to merge 1 commit into
DefectDojo:devfrom
svader0:harden-ssrf-redirect-hops
Open

svader0 wants to merge 1 commit into
DefectDojo:devfrom
svader0:harden-ssrf-redirect-hops

Conversation

@svader0

@svader0 svader0 commented Dec 3, 2026

Copy link
Copy Markdown
Collaborator

The outbound URL guard now also checks each request before it is sent, including each redirect hop. Before this, some connection setups skipped the check after the first URL. Adds regression tests. No change for requests to public addresses.

The safe adapter swaps in pinned connection classes, but some connection
setups never use them, so only the first URL was checked. Validate each
request in send(), which requests also calls for every redirect hop.
@Maffooch Maffooch added this to the 3.6.0 milestone Dec 4, 2026

@Maffooch Maffooch left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adversarial review: full tier, Opus

Tier: full (a backend change to the outbound URL guard, which is a security control). The diff is 2 files: dojo/utils_ssrf.py (+6) and unittests/test_utils_ssrf.py (+37). Base is dev. There are no migrations, no API shape changes and no UI.

CI read: ruff, Migration Graph, Rest Framework Unit Tests (both matrix legs), every User Interface Tests group, Performance Tests and the docker builds all pass. The red jobs are test-k8s (1.34.12 and v1.35.10) and Unit Tests Complete. The k8s job failed at "Test API auth call" with uwsgi in CrashLoopBackOff (OSError: write error). The same job failed across the merge queue on 2026-12-03 (#17121, #17126, #17131, #17132, #17026), and #17151, which raises the default uwsgi memory limit, merged afterwards. So the failure is not this PR's. The branch is 16 commits behind dev, so it needs a fresh run (merge dev or push) before it can go green.

Regression tests fail without the fix: I ran the module standalone against requests 2.34.2 and urllib3 2.8.0 (the pinned versions), once with the base utils_ssrf.py and once with the PR's.

  • test_private_target_blocked_through_proxy: the base raises ProxyError (the request goes to the proxy unchecked). The head raises SSRFError.
  • test_redirect_to_private_target_blocked_through_proxy: the base raises TooManyRedirects (no hop is checked). The head raises SSRFError on the first hop to 127.0.0.1.

Both tests can fail, so they are real coverage.

What I drove: a proxied make_ssrf_safe_session() with getaddrinfo patched, run against base and head (no stack, no live network).

Break attempts

  1. HTTPS through a proxy (CONNECT tunnel), which the PR's tests do not cover: https://127.0.0.1/. Base: sent to the proxy (ProxyError). Head: SSRFError. Held.
  2. Cloud metadata through a proxy: http://169.254.169.254/latest/. Base: sent. Head: SSRFError. Held.
  3. Alternate encodings of loopback through a proxy: 127.1, 0x7f000001, 2130706433, [::1], 0.0.0.0, and a redirect to [::ffff:127.0.0.1]. All are blocked on head and all reach the proxy on base. Held.
  4. Parser differential: http://example.com\@127.0.0.1/ and http://127.0.0.1:80@example.com/. requests rewrites the first to http://example.com/%5C@127.0.0.1/, and urlparse and urllib3 both read host example.com for both. The check and the proxy see the same host, so there is no bypass. Held.
  5. A redirect to a host with both public and private A records (93.184.216.34 and 10.0.0.5): head blocks on 10.0.0.5 because every address is checked. A redirect to file:///etc/passwd still ends in InvalidSchema. Held.
  6. No false positive: a public target answering 200 is allowed on head, both through the proxy and without one. Held, though no test in the PR covers it (R2).
  7. DNS rebinding through a proxy (static): send() resolves the name inside DefectDojo, and the proxy then resolves it again on its own. A name that answers public first and private second still gets through a proxy. The pinned connections close this window only on the direct path, but the module and session docstrings still say they close it on every request (R1). The window is narrower than before the PR (before, proxied requests had no check at all), so this is not a blocker. It does need saying.

Callers: the only caller in this repo is dojo/tools/risk_recon/api.py, and it already resolves its configured base URL locally before building the session. A proxy-only deployment without local DNS therefore failed there before this PR too, and the PR does not introduce that. The non-proxied path now makes one extra getaddrinfo per send(). That is acceptable for this caller, and keeping the check unconditional is reasonable defense in depth.

Performance: no querysets, no tasks. One DNS lookup per request is negligible.

Checked only statically: a real forward proxy (Squid or similar), and how the change behaves with trust_env proxy variables in a deployed container. These follow the same adapter.send() path as session.proxies, but I did not run them.

No screenshots: the change has no UI.

Findings

  • R1 suggestion this-pr dojo/utils_ssrf.py:4: the module docstring (lines 4-6, 14) and the make_ssrf_safe_session docstring (lines 177-183) still say every request is validated at socket creation and that DNS rebinding is closed. Through a proxy the check is now a pre-flight resolve in send(), and the proxy resolves the name again. State that limitation in both docstrings, next to the new comment at line 169.
  • R2 suggestion this-pr unittests/test_utils_ssrf.py:131: TestProxiedRequests proves the blocks but not the description's "no change for requests to public addresses". Add a test where a proxied request to a public host (patched getaddrinfo, HTTPAdapter.send returning 200) gets its response. Also add an https://127.0.0.1/ case so the CONNECT path is covered too.
  • R3 nit this-pr unittests/test_utils_ssrf.py:144: test_redirect_to_private_target_blocked_through_proxy patches HTTPAdapter.send, so the proxy is never consulted and the test passes the same without session.proxies. Name it for what it checks, for example test_each_redirect_hop_checked_before_send, or say in its docstring that the proxy setting is incidental.
  • R4 nit this-pr PR body: "some connection setups skipped the check after the first URL" understates the gap. Through a proxy, the session checked no URL at all; only RiskRecon's own pre-flight on its configured base URL ran. Reword it to say that requests sent through a proxy were not checked, and that each hop now is.

Recommendation

Changes required: 4 open this-pr findings (0 blockers, 2 suggestions, 2 nits). The fix itself is correct and closes a real gap: every attempt to reach a private address through a proxy or a redirect was blocked on head and allowed on base. After the fixes, merge dev so the k8s jobs re-run on the fixed base.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants