Validate user-supplied URLs in tool API clients#14868
Open
Maffooch wants to merge 1 commit into
Open
Conversation
Five tool API clients constructed their underlying HTTP session without validating the configured server URL and without using the SSRF-safe session adapter already established by `dojo/tools/risk_recon/api.py`. - api_sonarqube: validate `tool_config.url`; swap to make_ssrf_safe_session. - api_edgescan: validate `tool_config.url`; replace module-level `requests.get(...)` with a safe session held on `self`. - api_vulners: validate `tool_config.url` when supplied (the `vulners` library owns its own transport). - api_bugcrowd, api_cobalt: URL is hardcoded; only the session swap to `make_ssrf_safe_session` is needed. Two SonarQube fixtures used `http://localhost/`; updated them to a public URL so the importer tests continue to pass, and updated three assertion strings in `test_api_sonarqube_importer.py` plus the dummy hostname in `test_api_sonarqube_parser.py` accordingly. Co-Authored-By: Claude Opus 4.7 (1M context) <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.
Summary
Five tool API clients constructed their underlying HTTP session without validating the configured server URL. Three of them (
SonarQube,Edgescan,Vulners) accept the URL from aTool_Configurationset by an administrator;BugcrowdandCobaltuse a hardcoded public endpoint. Misconfigured or unreachable URLs (typo'd hostnames, leftover internal addresses, copy-pasted private IPs) produced raw connection errors instead of a clean validation message, and there was no defense-in-depth on the session itself.This change brings each client in line with the established
dojo/tools/risk_recon/api.pypattern:dojo/tools/api_sonarqube/api_client.py— callvalidate_url_for_ssrfontool_config.url; swaprequests.Session()→make_ssrf_safe_session().dojo/tools/api_edgescan/api_client.py— same; the per-callrequests.get(...)is replaced withself.session.get(...)so the same safe session handles every request.dojo/tools/api_vulners/api_client.py— validatetool_config.urlwhen supplied (thevulnerslibrary handles its own transport, so no session swap).dojo/tools/api_bugcrowd/api_client.pyanddojo/tools/api_cobalt/api_client.py— URL is hardcoded, so just swap tomake_ssrf_safe_session()for defense-in-depth.unittests/test_tool_api_clients_ssrf.pycovers each client. Two existing SonarQube fixtures (unit_sonarqube_toolConfig1.json/toolConfig2.json) usedhttp://localhost/and had to move to a publicly routable URL to keep the existing importer tests working; the three assertion strings intest_api_sonarqube_importer.pythat depended on the literalhttp://localhost/prefix and the dummy hostname intest_api_sonarqube_parser.pywere updated accordingly.Test plan