fix(tools): re-validate redirects and pin peer IP to close SSRF bypass#6038
Draft
theCyberTech wants to merge 2 commits into
Draft
fix(tools): re-validate redirects and pin peer IP to close SSRF bypass#6038theCyberTech wants to merge 2 commits into
theCyberTech wants to merge 2 commits into
Conversation
validate_url checked the URL string but ScrapeWebsiteTool and ScrapeElementFromWebsiteTool then fetched with requests' default allow_redirects=True, so a public host that 302-redirected to an internal address reached it without re-validation. The resolved IPs were also discarded, leaving a DNS time-of-check/time-of-use gap. Add crewai_tools.security.safe_requests: - SSRFProtectedAdapter re-runs validate_url on every send, including each redirect hop (Session.send calls the adapter per hop). - Connections validate the actual connected peer IP at connect time, so the IP that was authorised is the IP that is used (closes the DNS-rebinding gap). Route the two direct-fetch scrape tools through safe_get and add tests. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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
validate_url(crewai_tools/security/safe_path.py) inspects the URL string it is handed, butScrapeWebsiteToolandScrapeElementFromWebsiteToolthen fetched withrequests.get(..., allow_redirects=True). Two gaps followed from that decoupling:302 Location: <internal-address>was followed to the internal target without re-validation, turning the tools into an SSRF proxy for the worker's network (incl. RFC1918 ranges and169.254.169.254cloud metadata, which the validator's own blocklist explicitly covers).validate_urlresolved the host viagetaddrinfo, then discarded the IPs and returned the URL string;requestsre-resolved at connect time, so the IP that was checked was not necessarily the IP that was used.This is a bypass of a CrewAI-shipped SSRF control (the validator was introduced as a security fix, CVE-2026-2286).
Fix
New
crewai_tools/security/safe_requests.pyvalidates at the connection layer, where the actual connection is made:SSRFProtectedAdapter.send()re-runsvalidate_urlon every request.requests.Session.sendinvokes the adapter once per redirect hop, so eachLocationis validated before it is followed → closes the redirect arm._SafeHTTP[S]Connectionvalidate the actual connected peer IP (getpeername()) immediately afterconnect(). The IP that was authorised is the IP the socket uses → closes the DNS-rebinding gap.safe_get()is a drop-in replacement forrequests.get. TheCREWAI_TOOLS_ALLOW_UNSAFE_PATHSescape hatch is honored consistently.ScrapeWebsiteToolandScrapeElementFromWebsiteToolnow fetch throughsafe_get.Scope
WebsiteSearchTool/RagToolfetch through the RAG/embedchain loader layer (not a directrequests.get); that path is not covered by thisrequests-based utility and is flagged for a follow-up audit.Testing
tests/utilities/test_safe_requests.py(new): per-hop redirect re-validation, connection peer guard (private/metadata blocked, public allowed, escape hatch, simulated rebind), adapter mounting.pytest tests/utilities/test_safe_requests.py tests/utilities/test_safe_path.py→ 35 passed.ruff checkclean.ScrapeWebsiteTool._run(website_url="http://169.254.169.254/latest/meta-data/")is now blocked.🤖 Generated with Claude Code