Skip to content

fix(agent/tool): compare hostnames case-insensitively in DoPinned guard - #21171

Merged
yuzhichang merged 1 commit into
infiniflow:mainfrom
xugangqiang:fix-dopinned-host-case-insensitive
Oct 20, 2026
Merged

yuzhichang merged 1 commit into
infiniflow:mainfrom
xugangqiang:fix-dopinned-host-case-insensitive

Conversation

@xugangqiang

Copy link
Copy Markdown
Contributor

What

HTTPHelper.DoPinned rejected pinning when the URL host differed in case from originalHost, even though they are the same DNS name.

Why

DoPinned validates that the URL host matches the validated originalHost before pinning the connection to a resolved IP (defense in depth against SSRF / DNS-rebinding). It compared the two hosts with ==, which is case-sensitive. DNS hostnames are case-insensitive, so a legitimate, DNS-equivalent spelling — e.g. a user-typed EXAMPLE.TEST vs the resolver's lowercased example.test — was wrongly refused with http_helper: DoPinned url host ... != originalHost ... (refusing to pin — would break TLS SNI / cert check). This is the same class of bug fixed in internal/mcp/client (PR #21150 review): hostname comparisons must be case-insensitive.

How

  • internal/agent/tool/http_helper.go: compare with strings.EqualFold(u.Hostname(), originalHost) instead of ==. A genuinely different host is still refused.
  • This aligns the guard with the existing convention already used by the syncer connectors (moodle.go, bitbucket.go, etc.), which compare hostnames with strings.EqualFold.

How tested (TDD)

  • RED first: new TestHTTPHelper_DoPinnedAcceptsCaseInsensitiveHost fails before the fix — DoPinned rejects EXAMPLE.TEST vs example.test. It stands up a local httptest server and asserts the pinned request completes (status 200) once the guard accepts the case-insensitive match.
  • GREEN after fix.
  • Regression: full internal/agent/tool unit tier and the integration-go tier pass; existing DoPinned tests (SNI/cert preservation, proxy bypass, mismatched-host refusal) still pass.

Risk / notes

  • Behavior-preserving for the genuinely-mismatched-host path (still refused).
  • No config or API change; single-line comparison fix plus test.

🤖 Generated with CodeBuddy Code

DoPinned refused to pin when the URL host differed in case from
originalHost (e.g. a user-typed "EXAMPLE.TEST" vs the resolver's
lowercased "example.test"), even though they are the same DNS name.
DNS hostnames are case-insensitive, so compare them with
strings.EqualFold instead of ==.

A genuinely different host is still refused by the existing
TestHTTPHelper_DoPinnedRefusesMismatchedURLHost.

Add TDD test TestHTTPHelper_DoPinnedAcceptsCaseInsensitiveHost (RED before
implementation); existing DoPinned tests (SNI/cert preservation, proxy
bypass, mismatched-host refusal) still pass.
@xugangqiang xugangqiang added the ci Continue Integration label Oct 19, 2026
@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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: 8eb6fd60-80cd-4b11-81fa-2a7c9cf60d98
📥 Commits

Reviewing files that changed from the base of the PR and between 838cbf4 and 98dc06a.

📒 Files selected for processing: 2
  • internal/agent/tool/http_helper.go
  • internal/agent/tool/http_helper_test.go
📝 Walkthrough

DoPinned now compares the URL hostname with originalHost without regard to letter case. A test verifies that an uppercase URL hostname succeeds when originalHost is lowercase.

Changes: Host validation

Layer / File(s) Summary
Case-insensitive host matching
internal/agent/tool/http_helper.go, internal/agent/tool/http_helper_test.go
DoPinned accepts hostnames that differ from originalHost only by letter case. A test verifies that an uppercase hostname returns HTTP 200.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested reviewers: yuzhichang

Merge Risk: ⚪ Minimal · up to 98dc0

The change permits hostnames that differ only in letter case while retaining the pinned-IP connection. No concrete merge-blocking risk remains.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: making hostname comparison case-insensitive in the DoPinned guard.
Description check Passed The description clearly explains the problem, reason, implementation, testing, and risk. It does not use the template's exact "### Summary" heading, but it provides the required summary information an…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files.
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.
Full details: Description check

Explanation

The description clearly explains the problem, reason, implementation, testing, and risk. It does not use the template's exact "### Summary" heading, but it provides the required summary information and is otherwise complete.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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 the host by name,
Uppercase letters pass the same.
A pinned request now finds its way,
A test confirms the code today.
The rabbit hops, then guards the gate.

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

@yuzhichang
yuzhichang merged commit d7ecac5 into infiniflow:main Oct 20, 2026
6 checks passed
@xugangqiang
xugangqiang deleted the fix-dopinned-host-case-insensitive branch November 26, 2026 09:23
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