You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[deep-review][duplication] D8: Loopback host check duplicated in 3 places with subtly different rules #371
The notion "is this URL/IP a loopback?" is implemented three times across the codebase, each with slightly different semantics.
Where
src/OpenClaw.Shared/Mcp/McpHttpServer.cs:340-358 — IsHostAllowed: accepts 127.0.0.1[:port], localhost[:port], [::1]:port exactly. Used as the Host-header allowlist for DNS-rebinding mitigation.
src/OpenClaw.Shared/Mcp/McpHttpServer.cs:136-140 — IPAddress.IsLoopback(RemoteEndPoint) — checks the connecting socket, not a string.
src/OpenClaw.Shared/LocalGatewayUrlClassifier.cs — IsLocalGatewayUrl: a broader check including localhost, 127.*, 0.0.0.0, and WSL-typical addresses. Used to mark a gateway record as IsLocal.
Plus inline checks in:
src/OpenClaw.Tray.WinUI/Helpers/GatewayChatUrlBuilder.cs — when deciding if a chat URL needs TLS warning (related to C9).
src/OpenClaw.WinNode.Cli/Program.cs:157-168 — off-loopback refusal when an explicit --mcp-url points off 127.0.0.1.
Why it matters
Each check answers a slightly different question:
"Is the bound socket loopback?" (security-critical for MCP)
"Is the user-provided URL loopback-ish?" (UX hint for the chat URL)
"Is this a local-WSL-style gateway?" (classification for the gateway registry)
These really are different questions, so consolidating into a single boolean would lose information. But the underlying parsing (extract host, compare to literal 127.0.0.1 / localhost / [::1]) is duplicated.
Verified the three sites against the codebase. Each one does answer a genuinely different question:
Site
Question asked
Note
McpHttpServer:IsHostAllowed
"Is the Host header ≈ 127.0.0.1/localhost/[::1]?"
DNS-rebinding defence — strict allowlist
McpHttpServer:IPAddress.IsLoopback
"Is the connecting socket loopback?"
Socket-layer check, no string parsing
LocalGatewayUrlClassifier:IsLocalGatewayUrl
"Is this gateway URL local/WSL-ish?"
Broader: covers 0.0.0.0, WSL IPs, 127.*
GatewayChatUrlBuilder:uri.IsLoopback
"Should the chat URL skip the TLS hint?"
Uri.IsLoopback — correctly delegates to the BCL
The dangerous duplication is really only between IsHostAllowed and any future expansion of C9 (TLS warning for ws:// gateways). A LoopbackClassifier helper as proposed would:
Make IsHostAllowed testable in isolation (currently only tested via McpHttpServer integration tests).
Give C9 a single host-string parser to extend with IsPrivateNetworkUrl.
Centralise the IPv6-bracket-strip logic ([::1]:port → ::1) which is re-implemented at each site.
The uri.IsLoopback call in GatewayChatUrlBuilder is idiomatic and should stay as-is — the BCL already gets this right.
Closing during the post-refactor deep-review cleanup. Loopback host classification is consolidated into #372 for a fresh bounded audit. This keeps the signal while reducing stale one-off issue noise.
Activity
github-actions commentedon May 17, 2026
🤖 This is an automated response from Repo Assist.
Verified the three sites against the codebase. Each one does answer a genuinely different question:
McpHttpServer:IsHostAllowed127.0.0.1/localhost/[::1]?"McpHttpServer:IPAddress.IsLoopbackLocalGatewayUrlClassifier:IsLocalGatewayUrl0.0.0.0, WSL IPs,127.*GatewayChatUrlBuilder:uri.IsLoopbackUri.IsLoopback— correctly delegates to the BCLThe dangerous duplication is really only between
IsHostAllowedand any future expansion of C9 (TLS warning forws://gateways). ALoopbackClassifierhelper as proposed would:IsHostAllowedtestable in isolation (currently only tested viaMcpHttpServerintegration tests).IsPrivateNetworkUrl.[::1]:port→::1) which is re-implemented at each site.The
uri.IsLoopbackcall inGatewayChatUrlBuilderis idiomatic and should stay as-is — the BCL already gets this right.shanselman commentedon May 18, 2026
Closing during the post-refactor deep-review cleanup. Loopback host classification is consolidated into #372 for a fresh bounded audit. This keeps the signal while reducing stale one-off issue noise.