Skip to content

refactor(mcp): reject unvalidated redirect destinations - #20447

Merged
yuzhichang merged 1 commit into
infiniflow:mainfrom
6ba3i:fix/mcp-pinned-redirect-s1
Sep 30, 2026
Merged

yuzhichang merged 1 commit into
infiniflow:mainfrom
6ba3i:fix/mcp-pinned-redirect-s1

Conversation

@6ba3i

@6ba3i 6ba3i commented Sep 30, 2026

Copy link
Copy Markdown
Collaborator

MCP redirects could connect to hosts that had never passed the safety check. This change keeps every connection pinned to the validated host.

@coderabbitai

coderabbitai Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: fc8ac6b1-af87-4cd5-b28b-adeba1f24d7a

📥 Commits

Reviewing files that changed from the base of the PR and between 4ba6fdd and 05a93ca.

📒 Files selected for processing (3)
  • internal/utility/mcp_client_test.go
  • internal/utility/ssrf.go
  • internal/utility/ssrf_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The pinned HTTP client now normalizes hostnames and rejects invalid or unpinned dial destinations. Tests cover redirect behavior, Unicode hostnames, IPv6 literals, and FetchTools.

Changes

Pinned HTTP destination validation

Layer / File(s) Summary
Pinned destination validation
internal/utility/ssrf.go, internal/utility/ssrf_test.go
The client converts non-IP hostnames to IDNA ASCII and validates the dial host against the pinned hostname. Tests cover Unicode hostnames and IPv6 literals.
Redirect validation
internal/utility/ssrf_test.go, internal/utility/mcp_client_test.go
Tests verify that same-host redirects succeed and redirects to a separate host fail without sending a request to the target. The FetchTools test also checks that the redirect target receives no request.

Priority: ⬆️ High

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: jinhai-cn

Merge Risk: ⚪ Minimal · up to 05a93

The change rejects connections to unvalidated redirect hosts while preserving supported hostname formats. No concrete merge-blocking issue remains on the supplied evidence, subject to normal checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 05a93

The change strengthens destination validation, and no introduced or worsened security concern was identified. Remaining uncertainty concerns custom HTTP clients, deployment exposure, and transport behavior not directly exercised by the added tests.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The affected authority is server-side outbound networking used for MCP discovery and tool invocation. An attacker-controlled redirect previously could trigger the unmatched-host fallback; head rejects that route. Tenant, data-store, and environment exposure cannot be established from the inspected client sources.

Security Findings and Attack Paths

  • observed — The unmatched-destination fallback is a parent behavior removed by this PR, not a newly introduced condition. The inspected change strengthens that boundary; the supplied security assessment contains no retained findings, but its coverage is unknown.

Trust Boundaries and Controls

  • observed — Explicit caller-supplied HTTP clients bypass default pinned-client construction in discovery and invocation. This injection contract predates the PR; the normal server adapter constructor leaves the client unset, allowing the pinned default to be selected.
  • observed — The existing SSE endpoint transition validates endpoint-derived URLs and creates a fresh pinned client for a different host. This is a separately validated transition, unlike following a redirect through an unmatched-host fallback.
  • inferred — The per-client pin values are immutable across requests. HTTP and HTTPS connection establishment share the configured dial boundary, and reused connections do not create a new destination. Dedicated HTTPS, reuse, and concurrent lifecycle tests were not identified.

Resilience and Maintainability Implications

  • observed — Streamable HTTP sessions with an acquired session ID retain deferred, bounded cleanup independent of caller cancellation, using the same client. Session ownership and cleanup implementation are unchanged. Remote state created without a usable session ID cannot be assessed from client code alone.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: rejecting MCP redirect destinations that have not passed host validation.
Description check ✅ Passed The description explains the security issue and the intended fix. It provides the required summary information, although it omits the template's "### Summary" heading.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI

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

A rabbit checks each hostname’s trail
Before a request can leave the gate
Unicode paths become ASCII
Redirects meet the pinned address
Safe hops pass; stray hops wait
The rabbit thumps, then guards the route

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

@6ba3i
6ba3i requested a review from wangq8 September 30, 2026 06:26
@6ba3i 6ba3i added the ci Continue Integration label Sep 30, 2026
@wangq8
wangq8 requested a review from yuzhichang September 30, 2026 08:02
@yuzhichang
yuzhichang merged commit 8cfda89 into infiniflow:main Sep 30, 2026
6 checks passed
@6ba3i
6ba3i deleted the fix/mcp-pinned-redirect-s1 branch October 14, 2026 03:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants