Repository navigation
fix(agent/tool): compare hostnames case-insensitively in DoPinned guard - #21171
Conversation
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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
What
HTTPHelper.DoPinnedrejected pinning when the URL host differed in case fromoriginalHost, even though they are the same DNS name.Why
DoPinnedvalidates that the URL host matches the validatedoriginalHostbefore 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-typedEXAMPLE.TESTvs the resolver's lowercasedexample.test— was wrongly refused withhttp_helper: DoPinned url host ... != originalHost ... (refusing to pin — would break TLS SNI / cert check). This is the same class of bug fixed ininternal/mcp/client(PR #21150 review): hostname comparisons must be case-insensitive.How
internal/agent/tool/http_helper.go: compare withstrings.EqualFold(u.Hostname(), originalHost)instead of==. A genuinely different host is still refused.moodle.go,bitbucket.go, etc.), which compare hostnames withstrings.EqualFold.How tested (TDD)
TestHTTPHelper_DoPinnedAcceptsCaseInsensitiveHostfails before the fix —DoPinnedrejectsEXAMPLE.TESTvsexample.test. It stands up a localhttptestserver and asserts the pinned request completes (status 200) once the guard accepts the case-insensitive match.internal/agent/toolunit tier and theintegration-gotier pass; existingDoPinnedtests (SNI/cert preservation, proxy bypass, mismatched-host refusal) still pass.Risk / notes
🤖 Generated with CodeBuddy Code