Skip to content

Fix: allow any host for url for development - #16459

Merged
wangq8 merged 2 commits into
infiniflow:mainfrom
wangq8:bugfix/allow-any-host-for-url
Jun 30, 2026
Merged

wangq8 merged 2 commits into
infiniflow:mainfrom
wangq8:bugfix/allow-any-host-for-url

Conversation

@wangq8

@wangq8 wangq8 commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@wangq8 wangq8 added the ci Continue Integration label Jun 29, 2026
@coderabbitai

coderabbitai Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: eddb6ed7-3da2-4ff9-8850-03c28b147bc1

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@wangq8
wangq8 marked this pull request as ready for review June 29, 2026 11:16
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Jun 29, 2026
@wangq8
wangq8 marked this pull request as draft June 29, 2026 11:16
@wangq8
wangq8 marked this pull request as ready for review June 29, 2026 11:16

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
internal/utility/ssrf.go (1)

62-76: 🔒 Security & Privacy | 🔵 Trivial

Add an audit warning when the utility bypass is active.

AssertURLSafe feeds the MCP client pinning path, so ALLOW_ANY_HOST can silently allow and pin private or metadata IPs. Please emit an explicit warning when allowAny is 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 win

Update the docstring for the bypassed SSRF contract.

ALLOW_ANY_HOST now 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 | 🔵 Trivial

Add an audit warning when the crawler bypass is active.

ResolveAndValidate is the default resolver for CrawlerTool, 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

📥 Commits

Reviewing files that changed from the base of the PR and between 7c1edca and 06f073b.

📒 Files selected for processing (3)
  • common/ssrf_guard.py
  • internal/agent/tool/ssrf.go
  • internal/utility/ssrf.go

Comment thread common/ssrf_guard.py
Comment on lines +156 to +160
logger.warning(
"SSRF guard bypass enabled via %s; allowing URL host without validation: hostname=%r url=%r",
_ALLOW_ANY_HOST_ENV,
hostname,
url,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Suggested change
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

codecov Bot commented Jun 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (540acb4) to head (8ecb723).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wangq8
wangq8 merged commit 2018eec into infiniflow:main Jun 30, 2026
3 checks passed
xugangqiang pushed a commit to xugangqiang/ragflow that referenced this pull request Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant