fix(security): validate IPs on every redirect hop to prevent SSRF bypass#5711
Open
iris-clawd wants to merge 2 commits intomainfrom
Open
fix(security): validate IPs on every redirect hop to prevent SSRF bypass#5711iris-clawd wants to merge 2 commits intomainfrom
iris-clawd wants to merge 2 commits intomainfrom
Conversation
…ass (OSS-51) Adds a custom HTTPAdapter (_SSRFSafeAdapter) that intercepts every request — including redirect hops — and validates the resolved IP against the private/reserved blocklist before the connection proceeds. New public API: - safe_request_session(): returns a Session with the adapter mounted - safe_get(url, **kwargs): drop-in replacement for requests.get() that validates the initial URL AND every redirect destination Updated tools to use safe_get() instead of validate_url() + requests.get(): - ScrapeWebsiteTool - ScrapeElementFromWebsiteTool - WebPageLoader (RAG) Closes OSS-51
…ocks - Add proper type annotations to _SSRFSafeAdapter.send() to satisfy mypy - Add 'Any' import from typing - Update webpage_loader tests to mock safe_get instead of requests.get (the loader now uses safe_get for SSRF protection)
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
Fixes OSS-51 — SSRF bypass via redirect following in scraping tools.
Problem
validate_url()increwai_tools/security/safe_path.pyonly checked the initial URL beforerequests.get()fired. Sincerequests.get()follows redirects by default, an attacker could host a public URL that 302-redirects to an internal IP (e.g.169.254.169.254for cloud metadata) — the validator never saw the redirect target.This was reported by Casco Security and confirmed end-to-end on a live
app.crewai.comdeployment worker (CVE-2026-2286 follow-up).Fix
Added a custom
HTTPAdapter(_SSRFSafeAdapter) that intercepts every request — including redirect hops — and validates the resolved IP against the private/reserved blocklist before the connection proceeds.New public API:
safe_request_session()— returns arequests.Sessionwith the SSRF-safe adapter mountedsafe_get(url, **kwargs)— drop-in replacement forrequests.get()that validates both the initial URL and every redirect destinationUpdated tools:
ScrapeWebsiteTool— now usessafe_get()ScrapeElementFromWebsiteTool— now usessafe_get()WebPageLoader(RAG) — now usessafe_get()Tests
5 new tests in
test_safe_path.py:CREWAI_TOOLS_ALLOW_UNSAFE_PATHS=true) bypasses redirect checkAll 32 tests pass (27 existing + 5 new).
Note
Other tools that use third-party scraping services (Firecrawl, Spider, Scrapfly, etc.) are not affected — they delegate fetching to external APIs rather than using
requests.get()directly. The RAG PDF/docs loaders (pdf_loader.py,utils.py) also use barerequests.get()and could benefit from the same treatment in a follow-up.Closes OSS-51