Repository navigation
Conversation
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
left a comment
There was a problem hiding this comment.
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 raisesProxyError(the request goes to the proxy unchecked). The head raisesSSRFError.test_redirect_to_private_target_blocked_through_proxy: the base raisesTooManyRedirects(no hop is checked). The head raisesSSRFErroron 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
- 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. - Cloud metadata through a proxy:
http://169.254.169.254/latest/. Base: sent. Head:SSRFError. Held. - 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. - Parser differential:
http://example.com\@127.0.0.1/andhttp://127.0.0.1:80@example.com/. requests rewrites the first tohttp://example.com/%5C@127.0.0.1/, andurlparseand urllib3 both read hostexample.comfor both. The check and the proxy see the same host, so there is no bypass. Held. - A redirect to a host with both public and private A records (
93.184.216.34and10.0.0.5): head blocks on10.0.0.5because every address is checked. A redirect tofile:///etc/passwdstill ends inInvalidSchema. Held. - 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).
- 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
suggestionthis-prdojo/utils_ssrf.py:4: the module docstring (lines 4-6, 14) and themake_ssrf_safe_sessiondocstring (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 insend(), and the proxy resolves the name again. State that limitation in both docstrings, next to the new comment at line 169. - R2
suggestionthis-prunittests/test_utils_ssrf.py:131:TestProxiedRequestsproves 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 (patchedgetaddrinfo,HTTPAdapter.sendreturning 200) gets its response. Also add anhttps://127.0.0.1/case so the CONNECT path is covered too. - R3
nitthis-prunittests/test_utils_ssrf.py:144:test_redirect_to_private_target_blocked_through_proxypatchesHTTPAdapter.send, so the proxy is never consulted and the test passes the same withoutsession.proxies. Name it for what it checks, for exampletest_each_redirect_hop_checked_before_send, or say in its docstring that the proxy setting is incidental. - R4
nitthis-prPR 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.
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.