Skip to content

Validate user-supplied URLs in tool API clients#14868

Open
Maffooch wants to merge 1 commit into
bugfixfrom
fix/tool-api-client-url-validation
Open

Validate user-supplied URLs in tool API clients#14868
Maffooch wants to merge 1 commit into
bugfixfrom
fix/tool-api-client-url-validation

Conversation

@Maffooch
Copy link
Copy Markdown
Contributor

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 a Tool_Configuration set by an administrator; Bugcrowd and Cobalt use 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.py pattern:

  • dojo/tools/api_sonarqube/api_client.py — call validate_url_for_ssrf on tool_config.url; swap requests.Session()make_ssrf_safe_session().
  • dojo/tools/api_edgescan/api_client.py — same; the per-call requests.get(...) is replaced with self.session.get(...) so the same safe session handles every request.
  • dojo/tools/api_vulners/api_client.py — validate tool_config.url when supplied (the vulners library handles its own transport, so no session swap).
  • dojo/tools/api_bugcrowd/api_client.py and dojo/tools/api_cobalt/api_client.py — URL is hardcoded, so just swap to make_ssrf_safe_session() for defense-in-depth.

unittests/test_tool_api_clients_ssrf.py covers each client. Two existing SonarQube fixtures (unit_sonarqube_toolConfig1.json / toolConfig2.json) used http://localhost/ and had to move to a publicly routable URL to keep the existing importer tests working; the three assertion strings in test_api_sonarqube_importer.py that depended on the literal http://localhost/ prefix and the dummy hostname in test_api_sonarqube_parser.py were updated accordingly.

Test plan

  • `python manage.py test unittests.test_tool_api_clients_ssrf`
  • `python manage.py test unittests.tools.test_api_sonarqube_importer unittests.tools.test_api_sonarqube_parser unittests.test_api_sonarqube_updater`
  • `python manage.py test unittests.tools.test_api_edgescan_importer unittests.tools.test_api_cobalt_importer unittests.tools.test_api_bugcrowd_importer unittests.tools.test_api_vulners_parser`
  • `python manage.py check`
  • `ruff check . --fix`

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>
Copy link
Copy Markdown
Member

@valentijnscholten valentijnscholten left a comment

Choose a reason for hiding this comment

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

commented via DM

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