fix(webfetch): block loopback/private/link-local/metadata hosts (SSRF guard)#4
fix(webfetch): block loopback/private/link-local/metadata hosts (SSRF guard)#4NubsCarson wants to merge 1 commit into
Conversation
… guard) webfetch can be driven by autonomous agents, so a bare GET must not be usable to reach internal services. Reject loopback (127.0.0.0/8, ::1), private (10/8, 172.16/12, 192.168/16), link-local + cloud metadata (169.254/16, 169.254.169.254), IPv6 ULA/link-local, and *.local/*.internal/localhost hosts before fetching. Public hosts are unaffected.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro 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 PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window. Feel free to open a new pull request that follows our guidelines. |
|
Reopened. Note: this repo has Issues disabled, so the pr-standards bot's "link an issue" requirement cannot be satisfied here — requesting a manual maintainer review. The change is a defensive SSRF guard (blocks loopback/private/link-local/cloud-metadata hosts before webfetch's |
Issue for this PR
Closes # — N/A (issues are disabled on this repository, so there's no issue to link; happy to file one elsewhere if a maintainer prefers).
Type of change
What does this PR do?
webfetchonly checks the URL scheme (http/https) — there's no host filtering, and redirects are followed by default. Becausewebfetchcan be driven by autonomous agents (and is reachable via prompt injection), a bare GET can be aimed at internal services: loopback, private LAN ranges, or cloud metadata at169.254.169.254. The response body is handed back to the model, so it's a usable SSRF / internal-data-exfil primitive.This adds
isBlockedFetchHost()and checks the resolved URL hostname before fetching, rejecting:localhost/*.local/*.internal, IPv4 loopback127/8+0.x, private10/8/172.16-31/192.168/16, link-local + metadata169.254/16, and IPv6::1/::/ULAfc00::/7/link-localfe80::/10. Public hosts are unaffected. It's a string/range guard on the URL host (the common high-value targets); it intentionally doesn't attempt full DNS-rebinding-time protection.How did you verify your code works?
Unit-tested the host classifier across public hosts (allowed, incl.
8.8.8.8and afc-…domain) and internal hosts (blocked: localhost, 127/10/192.168/172.16, 169.254.169.254,[::1]). Ran it live in a downstream deployment: public crypto/FX/weather fetches still work with zero false-positives, and internal targets are refused.Checklist