fix(security): browser redirect SSRF bypass + explicit URL scheme whitelist - #3046
fix(security): browser redirect SSRF bypass + explicit URL scheme whitelist#30460xbyt4 wants to merge 2 commits into
Conversation
…it scheme whitelist Two related SSRF hardening fixes: 1. browser_navigate: After Chromium follows redirects internally, re-validate the final URL with is_safe_url(). A public URL that 302-redirects to http://169.254.169.254/ (cloud metadata) was not caught because the pre-flight check only validated the initial URL. Session is closed if the redirect target is blocked. 2. url_safety: Add explicit scheme whitelist (http/https only). Previously javascript:, data:, file:// URLs were blocked by accident (no hostname parsed → returned False). Now they are explicitly rejected with a log message, preventing future regressions if the hostname check changes.
Ensures this PR works independently without requiring PR NousResearch#3041 (pre-navigation SSRF check) to be merged first.
1 similar comment
|
Recommendation: close this PR as superseded. I verified this against current upstream/main at
I also attempted a local diagnostic rebase of this PR onto current upstream. It conflicts exactly in What can still be salvaged:
Verification I ran on current upstream: scripts/run_tests.sh tests/tools/test_browser_ssrf_local.py tests/tools/test_url_safety.py -- -k "redirect or scheme or unsupported or always_blocked or safe_url"Result: 14 passed, 0 failed. Based on that, I recommend closing this PR as superseded and opening a fresh small test PR only if the extra explicit scheme cases are desired. |
|
Recommendation: close this PR as superseded. I reviewed PR head Validation:
The linked issue #7342 is now narrowed to DNS-pinning / DNS-rebinding / connection-level TOCTOU. This PR's redirect and scheme changes are already superseded by newer upstream code and do not address that remaining scope. Signed: GPT-5.5-xhigh in Codex |
|
This looks implemented on current main by newer security hardening. Automated hermes-sweeper review. Evidence:
The prior discussion noting that this PR was superseded by newer upstream logic matches the current source. Thanks to @0xbyt4 for the original hardening work and threat writeup; the same behaviors are now covered on main in the integrated implementation. |
Summary
Two related SSRF hardening fixes for the browser and URL safety modules:
1. Post-navigation redirect validation (CRITICAL)
browser_navigate()validated the initial URL withis_safe_url()but Chromium follows HTTP redirects internally. An attacker-controlled URL likehttps://evil.comthat 302-redirects tohttp://169.254.169.254/latest/meta-data/bypassed the pre-flight SSRF check.Now the final URL returned by Chromium is re-validated after navigation. If the redirect target is a private/internal address, the browser session is closed and an error is returned.
web_toolsandvision_toolsalready had redirect protection (httpx event hooks). The browser tool was the only one missing it because agent-browser is a subprocess — CDP doesn't expose redirect events, so post-navigation validation is the correct approach.2. Explicit URL scheme whitelist (HIGH)
is_safe_url()inurl_safety.pyblockedjavascript:,data:,file://URLs by accident — they had no hostname, so the hostname check returnedFalse. This was fragile — if the hostname check logic ever changed, these dangerous schemes could slip through.Added explicit
parsed.scheme not in ("http", "https")check before hostname resolution. Now unsupported schemes are rejected with a clear log message.Test plan
tests/tools/test_url_safety.py— all passedtests/tools/test_website_policy.py— 22/22 passedtests/tools/test_browser_cdp_override.py— 4/4 passedtests/tools/test_vision_tools.py— all passed