Repository navigation
fix(crewai-tools): block SSRF and cookie leak in SeleniumScrapingTool - #9673
Vidit Ostwal (Vidit-Ostwal) wants to merge 4 commits into
Conversation
Strix Security ReviewTo fix before merging (1)
PR summary: Hardens SeleniumScrapingTool against SSRF and cookie leakage: requested and post-redirect URLs are validated against the shared private/reserved-address guard, backslash-containing URLs are rejected, and the configured cookie is only sent when the loaded host matches its domain (or the fixed website_url host). Review summaryThe backslash-in-authority bypass reported in the previous review is fixed: the tool now rejects any URL containing a backslash before validation and navigation, and the pre-navigation guard is the shared default-deny URL validator, which I confirmed blocks decimal/octal/hex and abbreviated IPv4, IPv4-mapped and NAT64 IPv6, DNS-name forms of loopback/metadata, file:// and non-http schemes. Cookie scoping is also effective — the cookie is only attached after the landed host matches its domain (or the fixed website_url host), so no path sends it to a model-chosen host, and the unconditional redirect re-validation closes the off-domain redirect case. The only confirmed issue is minor: when the post-navigation check rejects a landing URL, the resulting error text quotes Chrome's final internal URL, including host, path, query and resolved private IP, which hands the caller internal naming it never supplied. Redirect-driven and rebinding blind requests to internal hosts remain as the authors documented them in the PR description. 1 resolved findingRuled out (1)
Review history (2)
Fixed the findings? re-run the review, or tag Review 2 on this PR · Reviewed by Strix |
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Automations to automatically generate PRs for you. |
Validate the target URL with validate_url before navigating and again on the post-redirect driver.current_url, so internal and metadata addresses are rejected. Attach the configured cookie only when the loaded host matches the cookie's domain (or the fixed website_url's host). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
126e641 to
25a410d
Compare
urlparse (used by validate_url) and Chrome parse the authority differently when a backslash is present, so the validated host could differ from the host navigated to. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Strix (@strix-security) please re-review the latest commits. The backslash-in-authority bypass is fixed in 02162b5: backslashes are now rejected before validate_url and driver.get. DNS rebinding and redirect requests remain a known limit, noted in the PR description, with a filtering proxy planned as follow-up. |
| self.driver.get(url) | ||
| time.sleep(sleep_time) | ||
| # Chrome follows redirects itself, so re-check where it actually landed. | ||
| loaded_url = validate_url(self.driver.current_url) |
There was a problem hiding this comment.
🔵 LOW: The redirect check hands the model the internal URL it just refused to read
TL;DR: A page the agent scrapes can bounce it to an internal address, and the tool's error text reports that internal host, path, query string and private IP back to anyone who controls the scraped URL. Chrome is allowed to follow the redirect, the landing URL is then rejected by validate_url, and the rejection message is returned as the tool result. Raising a fixed, generic message from the post-navigation checks instead of passing the validator's text through keeps the details in the log where operators can see them.
Cause, impact and fix
Cause: _run has no boundary between operator diagnostics and what the model sees: any exception raised inside _make_request is formatted into the tool result by return f"Error scraping website: {e!s}". validate_url in lib/crewai-tools/src/crewai_tools/security/safe_path.py builds its rejection as URL '<url>' resolves to private/reserved IP <ip>, which is written for an operator reading logs. On the post-navigation check the argument is self.driver.current_url, i.e. whatever URL the internal service's own redirect sent the browser to, so the string carries a hostname, path, query and resolved address the caller never supplied. The same text reaches the model from the second check after the cookie re-navigation, and the pre-navigation check echoes the resolved address of the requested host.
Impact: An attacker who can influence the URL an agent scrapes (a link in a document, an inbox, a search result, a page they host) learns internal hostnames, paths, query strings and private IP addresses of services the agent's network can reach, without those details ever appearing in their own request. That is reconnaissance that makes a follow-up attack on the internal network easier while the guard itself correctly blocks the read.
Fix: Do not let the guard's diagnostic text reach the model. Wrap both post-navigation validate_url(self.driver.current_url) calls in _make_request so a rejection raises a fixed message such as Refused to read the page: the URL redirected to a private or reserved address, chaining the original exception with from exc so operators still get the URL and address in logs and tracebacks. Apply the same treatment to the pre-navigation check, which currently echoes the resolved address of the requested host. Longer term the planned proxy that stops the internal request from being made at all removes the underlying primitive rather than only the reporting channel.
🔵 SeleniumScrapingTool returns the internal redirect landing URL (host, path, query, private IP) to the model
🔵 SeleniumScrapingTool returns the internal redirect landing URL (host, path, query, private IP) to the model
Severity: LOW
TL;DR: The new post-navigation validate_url(self.driver.current_url) check rejects an internal landing page with a message that quotes that URL and its resolved private IP, and _run returns that message verbatim to the model.
Impact: An attacker who controls the URL an agent scrapes can bounce a public page to an internal host and read back, in the tool's error text, that host's name, path, query string and private IP — internal network details the attacker never supplied.
Root cause:
- The tool has no boundary between operator diagnostics and model-visible output:
_runturns any exception into the tool result, so a validator message written to describe a blocked target is handed straight to the model. validate_urlinterpolates the URL it rejected together with the resolved private IP, and the new post-navigation call passes it Chrome's final landing URL instead of the caller's input.- The landing URL is produced by the internal host's own redirect, so it carries a hostname, path, query and address the caller never supplied; the leak exists only because this check runs after Chrome has already followed the redirect.
Prompt to fix with AI
This is a security vulnerability found during a code review.
Vulnerability: SeleniumScrapingTool returns the internal redirect landing URL (host, path, query, private IP) to the model
Severity: LOW
CWE: CWE-209
**TL;DR:** The new post-navigation `validate_url(self.driver.current_url)` check rejects an internal landing page with a message that quotes that URL and its resolved private IP, and `_run` returns that message verbatim to the model.
**Impact:** An attacker who controls the URL an agent scrapes can bounce a public page to an internal host and read back, in the tool's error text, that host's name, path, query string and private IP — internal network details the attacker never supplied.
**Root cause:**
- The tool has no boundary between operator diagnostics and model-visible output: `_run` turns any exception into the tool result, so a validator message written to describe a blocked target is handed straight to the model.
- `validate_url` interpolates the URL it rejected together with the resolved private IP, and the new post-navigation call passes it Chrome's final landing URL instead of the caller's input.
- The landing URL is produced by the internal host's own redirect, so it carries a hostname, path, query and address the caller never supplied; the leak exists only because this check runs after Chrome has already followed the redirect.
Location: lib/crewai-tools/src/crewai_tools/tools/selenium_scraping_tool/selenium_scraping_tool.py:212-215
Context: post-redirect check: replace the validator message with a generic rejection
```
// Before:
self.driver.get(url)
time.sleep(sleep_time)
# Chrome follows redirects itself, so re-check where it actually landed.
loaded_url = validate_url(self.driver.current_url)
// After:
self.driver.get(url)
time.sleep(sleep_time)
# Chrome follows redirects itself, so re-check where it actually landed.
# Its message is returned to the model, so do not let it name the host,
# path or resolved address Chrome ended up on.
try:
loaded_url = validate_url(self.driver.current_url)
except ValueError as exc:
raise ValueError(
"Refused to read the page: the URL redirected to a private or "
"reserved address."
) from exc
```
Location: lib/crewai-tools/src/crewai_tools/tools/selenium_scraping_tool/selenium_scraping_tool.py:228-228
Context: second post-navigation check, same message path after the cookie re-navigation
```
validate_url(self.driver.current_url)
```
Location: lib/crewai-tools/src/crewai_tools/tools/selenium_scraping_tool/selenium_scraping_tool.py:149-150
Context: model-visible sink: the exception text becomes the tool result
```
except Exception as e:
return f"Error scraping website: {e!s}"
```
How to fix:
Do not let the model see the guard's diagnostic text on the post-redirect path. Wrap both post-navigation checks (`_make_request` after `driver.get`) so a rejection raises a fixed, generic message such as "refused: the URL redirected to a private or reserved address", chaining the original exception with `from exc` so operators still get the URL in logs. The same care is worth applying to the pre-navigation check, whose message currently echoes the resolved address of the requested host; a generic message leaks nothing while still failing closed. Longer term, the planned filtering proxy that stops the internal request from happening at all removes the underlying primitive rather than just the reporting channel.
Please fix this vulnerability. If you propose a fix, make it concise and minimal.React 👍 / 👎 to tune Strix for this repo. A repo collaborator (or the PR author) can resolve this thread to dismiss these findings.
| validate_url(url) | ||
|
|
||
| sleep_time = wait_time or 0 | ||
| self.driver.get(url) |
There was a problem hiding this comment.
🔒 Agentic Security Review
Severity: HIGH
Description: SeleniumScrapingTool treats validate_url as the SSRF boundary, but Chrome connects before that check can apply. validate_url(url) only resolves the hostname once via getaddrinfo. driver.get(url) then lets Chrome resolve the name and follow redirects on its own. A public URL that 302s to http://169.254.169.254/ or another private or link-local address is already requested by the tool host before validate_url(self.driver.current_url) runs. The same unpinned driver.get(url) runs again after add_cookie. Nothing checks the connected peer, so a later DNS answer can also point Chrome at a blocked IP while the document hostname still passes validate_url.
Impact: Any caller or agent that can pass website_url (the default schema), or a site that the tool was already pointed at, can make the tool process open a browser connection to a private, loopback, or link-local address, including cloud metadata. No credential is required on the tool host; the attacker only needs the fetched origin or its DNS. A redirect whose final document URL is a literal private address does not return the page: validate_url raises first, _get_content is skipped, and the configured cookie is not attached. When the document hostname still validates (DNS rebinding or split resolvers), _get_content returns whatever Chrome loaded, which is an internal HTTP response and, on IMDSv1, instance credentials. The post-cookie navigation repeats that unpinned fetch and will send the configured cookie when the hostname matches the cookie domain. That is a real bypass of the SSRF boundary this library enforces for other HTTP clients with safe_get and SSRFProtectedAdapter.
Remediation: Do not use a post-navigation current_url check as the SSRF boundary. Block private and reserved peers on every browser connection before the request is sent, for the initial navigation, every redirect, and the reload after add_cookie, using the same is_blocked_ip decision as SSRFProtectedAdapter (a filtering proxy or equivalent). Keep refusing to return the body when the final URL is not allowed.
Fixes OSS-260 (GHSA-35fj-mp4x-cp58, GHSA-x2h6-x2q7-9q3r).
Problem
SeleniumScrapingToolhad two issues:driver.get. The sharedvalidate_urlguard was never called, so the model could reach internal and cloud-metadata addresses (incomplete fix for CVE-2026-2286).Changes
_make_requestcallsvalidate_urlon the requested URL before navigating. This covers both model-supplied and constructor-fixed URLs.driver.current_urlafter load, since Chrome follows redirects itself.domainor is a subdomain of it. A cookie with nodomainis bound to the fixedwebsite_urlhost. With neither, the cookie is withheld.Behavior change
A cookie with no
domain, used with a model-chosen URL, is no longer sent. That is the vulnerable setup.Known limits
Tests
Added tests for blocked internal URLs (metadata, loopback, localhost, RFC1918), redirect to an internal address, and cookie scoping (foreign host, off-domain redirect, own domain and subdomain, domain-less cookie). The existing tests stub
validate_url, and the existing fake driver gainedcurrent_url.Testing
20 tests pass locally with
seleniuminstalled.ruffandmypyare clean.🤖 Generated with Claude Code