Repository navigation
Fix: allow any host for url for development - #16459
Conversation
|
Important Review skippedDraft detected. 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:
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (3)
internal/utility/ssrf.go (1)
62-76: 🔒 Security & Privacy | 🔵 TrivialAdd an audit warning when the utility bypass is active.
AssertURLSafefeeds the MCP client pinning path, soALLOW_ANY_HOSTcan silently allow and pin private or metadata IPs. Please emit an explicit warning whenallowAnyis true.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/utility/ssrf.go` around lines 62 - 76, Add an explicit audit warning in AssertURLSafe when allowAnyHost() enables the bypass, since ALLOW_ANY_HOST can silently permit private or metadata IPs. Update the allowAny handling near the hostname resolution logic to emit a warning once before continuing. Use the AssertURLSafe and allowAnyHost symbols to place the change in the SSRF utility path that feeds MCP client pinning. Keep the existing validation behavior unchanged when allowAny is false.common/ssrf_guard.py (1)
154-173: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUpdate the docstring for the bypassed SSRF contract.
ALLOW_ANY_HOSTnow skips the unconditional “every address is globally routable” guarantee. Please document that exception so callers do not rely on public-IP pinning while the dev override is active.Proposed docstring update
- 3. **Every** address returned by ``getaddrinfo`` is globally routable + 3. Unless ``ALLOW_ANY_HOST`` enables the development bypass, **every** + address returned by ``getaddrinfo`` is globally routable (``ip.is_global``). This is an allowlist approach: it catches private, loopback, link-local, reserved, multicast, and all other special-purpose ranges rather than individual deny-list flags. @@ - Returns ``(hostname, resolved_ip)`` — the first validated public IP string + Returns ``(hostname, resolved_ip)`` — the first validated public IP string + (or the first resolved IP while ``ALLOW_ANY_HOST`` is enabled) — so the caller can **pin** that address in its HTTP client and prevent🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@common/ssrf_guard.py` around lines 154 - 173, Update the docstring for the SSRF host-validation path to document the ALLOW_ANY_HOST bypass exception. In the logic around _allow_any_host(), socket.getaddrinfo(), and the host/IP checks in the SSRF guard function, make it clear that when the bypass is enabled the code skips the normal public-IP pinning/global-routable guarantee. Keep the docstring aligned with the actual behavior so callers do not assume unrestricted validation is still enforced under the dev override.internal/agent/tool/ssrf.go (1)
87-100: 🔒 Security & Privacy | 🔵 TrivialAdd an audit warning when the crawler bypass is active.
ResolveAndValidateis the default resolver forCrawlerTool, so this branch can silently allow and pin private or metadata targets if the dev flag leaks into a deployed environment. Emit a warning when the branch is taken.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/agent/tool/ssrf.go` around lines 87 - 100, The allowAnyHost() branch in ResolveAndValidate currently bypasses SSRF validation silently, so add an audit warning when that path is taken. Update the ssrf resolver in ssrf.go to log a clear warning through the existing logging/audit mechanism before returning from the bypass branch, using the ResolveAndValidate and allowAnyHost symbols to locate the change. Keep the warning focused on the crawler bypass being active so deployment leaks are visible without changing the existing resolution behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@common/ssrf_guard.py`:
- Around line 156-160: The bypass warning in ssrf_guard should keep logging the
new flow, but stop including the raw user-supplied URL. Update the
logger.warning call in the SSRF guard bypass path to log only the env flag and
hostname, and remove the url argument from the message so embedded credentials
or tokens are not exposed.
---
Nitpick comments:
In `@common/ssrf_guard.py`:
- Around line 154-173: Update the docstring for the SSRF host-validation path to
document the ALLOW_ANY_HOST bypass exception. In the logic around
_allow_any_host(), socket.getaddrinfo(), and the host/IP checks in the SSRF
guard function, make it clear that when the bypass is enabled the code skips the
normal public-IP pinning/global-routable guarantee. Keep the docstring aligned
with the actual behavior so callers do not assume unrestricted validation is
still enforced under the dev override.
In `@internal/agent/tool/ssrf.go`:
- Around line 87-100: The allowAnyHost() branch in ResolveAndValidate currently
bypasses SSRF validation silently, so add an audit warning when that path is
taken. Update the ssrf resolver in ssrf.go to log a clear warning through the
existing logging/audit mechanism before returning from the bypass branch, using
the ResolveAndValidate and allowAnyHost symbols to locate the change. Keep the
warning focused on the crawler bypass being active so deployment leaks are
visible without changing the existing resolution behavior.
In `@internal/utility/ssrf.go`:
- Around line 62-76: Add an explicit audit warning in AssertURLSafe when
allowAnyHost() enables the bypass, since ALLOW_ANY_HOST can silently permit
private or metadata IPs. Update the allowAny handling near the hostname
resolution logic to emit a warning once before continuing. Use the AssertURLSafe
and allowAnyHost symbols to place the change in the SSRF utility path that feeds
MCP client pinning. Keep the existing validation behavior unchanged when
allowAny is false.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 766fa4d9-fb95-4257-b957-0feadb39ab95
📒 Files selected for processing (3)
common/ssrf_guard.pyinternal/agent/tool/ssrf.gointernal/utility/ssrf.go
| logger.warning( | ||
| "SSRF guard bypass enabled via %s; allowing URL host without validation: hostname=%r url=%r", | ||
| _ALLOW_ANY_HOST_ENV, | ||
| hostname, | ||
| url, |
There was a problem hiding this comment.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
Redact the raw URL from the bypass warning.
This new allowed-path log can include embedded credentials or query tokens from user-supplied URLs. Keep the new-flow warning, but log only the env flag and hostname.
As per coding guidelines, **/*.py: Add logging for new flows.
Proposed fix
logger.warning(
- "SSRF guard bypass enabled via %s; allowing URL host without validation: hostname=%r url=%r",
+ "SSRF guard bypass enabled via %s; allowing URL host without validation: hostname=%r",
_ALLOW_ANY_HOST_ENV,
hostname,
- url,
)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| logger.warning( | |
| "SSRF guard bypass enabled via %s; allowing URL host without validation: hostname=%r url=%r", | |
| _ALLOW_ANY_HOST_ENV, | |
| hostname, | |
| url, | |
| logger.warning( | |
| "SSRF guard bypass enabled via %s; allowing URL host without validation: hostname=%r", | |
| _ALLOW_ANY_HOST_ENV, | |
| hostname, | |
| ) |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@common/ssrf_guard.py` around lines 156 - 160, The bypass warning in
ssrf_guard should keep logging the new flow, but stop including the raw
user-supplied URL. Update the logger.warning call in the SSRF guard bypass path
to log only the env flag and hostname, and remove the url argument from the
message so embedded credentials or tokens are not exposed.
Source: Coding guidelines
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16459 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
No description provided.