Skip to content

fix(crewai-tools): block SSRF and cookie leak in SeleniumScrapingTool - #9673

Open
Vidit Ostwal (Vidit-Ostwal) wants to merge 4 commits into
mainfrom
viditostwal/oss-260-high-seleniumscrapingtool-reaches
Open

Vidit Ostwal (Vidit-Ostwal) wants to merge 4 commits into
mainfrom
viditostwal/oss-260-high-seleniumscrapingtool-reaches

Conversation

@Vidit-Ostwal

Copy link
Copy Markdown
Member

Fixes OSS-260 (GHSA-35fj-mp4x-cp58, GHSA-x2h6-x2q7-9q3r).

Problem

SeleniumScrapingTool had two issues:

  1. SSRF. URL checks were scheme/netloc only and the URL went straight to driver.get. The shared validate_url guard was never called, so the model could reach internal and cloud-metadata addresses (incomplete fix for CVE-2026-2286).
  2. Cookie leak. The configured cookie was added to whatever host loaded, including a model-chosen one.

Changes

  • _make_request calls validate_url on the requested URL before navigating. This covers both model-supplied and constructor-fixed URLs.
  • It validates driver.current_url after load, since Chrome follows redirects itself.
  • The cookie is attached only if the loaded host equals the cookie's domain or is a subdomain of it. A cookie with no domain is bound to the fixed website_url host. 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

  • The redirect check runs after Chrome has made the request. The response never reaches the model, but a blind request to an internal host can still happen. DNS rebinding and sub-resources (iframes, XHR) are not covered. Closing those needs Chrome flags or a proxy, as follow-up.

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 gained current_url.

Testing

20 tests pass locally with selenium installed. ruff and mypy are clean.

🤖 Generated with Claude Code

@strix-security

strix-security Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Strix Security Review

To 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 summary

The 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 finding
Ruled out (1)
  • Can a public page script a top-level navigation to an internal address that slips past the post-load URL check and gets scraped?
    Reproduced against headless Chrome with the PR's own code: the navigation either commits before current_url is read (so the check rejects it and nothing is scraped) or is still in flight when the element query runs, which yields no body element rather than the internal document, since there is no w…
Review history (2)
  • Review 2 · 02162b5 · Nov 23 14:12 UTC · Found 1 new Low Vulnerability · Fixed 1
  • Review 1 · 268d6fe · Nov 23 07:37 UTC · Found 1 Medium Vulnerability

Fixed the findings? re-run the review, or tag @strix-security in a PR comment to run a fresh review.

Review 2 on this PR · 02162b5 · requested Nov 23 14:05 UTC by @Vidit-Ostwal


Reviewed by Strix
Re-run review · Configure security review settings · Try a deeper review with @strix-security /deep

@linear

linear Bot commented Nov 23, 2026

Copy link
Copy Markdown

OSS-260

@mintlify

mintlify Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated
crewai 🟢 Ready View Preview Nov 23, 2026, 1:55 PM

💡 Tip: Enable Automations to automatically generate PRs for you.

@strix-security strix-security Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Strix flagged a new security finding below. See the pinned summary comment for the full PR status.

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>
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>
@Vidit-Ostwal

Copy link
Copy Markdown
Member Author

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.

@strix-security strix-security Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Strix flagged a new security finding below. See the pinned summary comment for the full PR status.

Comment on lines 212 to +215
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 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: _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.
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 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.

This branch was successfully deployed

1 active (outdated) deployment
staging - docs — 25a410d0 Deployed Nov 23, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant