Repository navigation
Refuse plain http to the name localhost - #5
Merged
Merged
Conversation
WithBaseURL allowed plain http for localhost, 127.0.0.1 and ::1. A name is looked up, and the lookup can reach DNS: when the hosts file does not list localhost, or when DNS comes first in nsswitch. The resolver then asks for localhost.<search domain> first, so whoever controls that zone can answer with another machine, which receives the token in clear text. A review reproduced this with the old code in a network namespace. Plain http is now allowed only when the host is exactly 127.0.0.1 or ::1. IP literals are never looked up, and net/http never proxies them. The host no longer needs lowercasing, which existed only so that net/http's proxy bypass matched "LOCALHOST". This breaks callers that pass http://localhost; they can use http://127.0.0.1, http://[::1] or https://localhost. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NYjhaGCRVp9GXLUuUZv8g1
This was referenced Nov 1, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WithBaseURLallowed plainhttpforlocalhost,127.0.0.1and::1. This PR drops the namelocalhost, so plainhttpis allowed only when the host is exactly127.0.0.1or::1.Why
localhostis a name, so it is looked up. The lookup can reach DNS when the hosts file does not listlocalhost, or whennsswitch.confputs DNS before files. The resolver (Go's own, and glibc's) then asks forlocalhost.<search domain>first. Whoever controls that zone can answer with another machine, and that machine receives the API token in clear text.A review reproduced this with the old code. The setup was an unprivileged network namespace, a fake DNS server, and a
CGO_ENABLED=0build:localhostline in the hosts file,http://localhost:8080sentAuthorization: Bearer …to 192.0.2.10.hosts: dns filesinnsswitch.conf, the token reached 192.0.2.10 even though the hosts file listedlocalhost.The new code refuses both URLs. IP literals are never looked up, and net/http never sends them through a proxy.
Changes
parseBaseURLaccepts plainhttponly for127.0.0.1and::1. The host is no longer lowercased. That step existed only so that net/http's proxy bypass matchedLOCALHOST.WithBaseURLand package docs, the example comment, the security guidance and the CHANGELOG (marked Breaking) are updated.TestBaseURLrows cover:http://localhostin several spellings, which is refused;https://localhost, which is still accepted;127.1,2130706433,[::ffff:127.0.0.1],[0:0:0:0:0:0:0:1],[::1%25lo]), which are refused;Review
A three-lens review ran on this change, and each finding was checked by a separate verifier:
httpURL dialed 127.0.0.1 or ::1, with no proxy, under both the default client and a cloned default transport.Follow-up when consumers upgrade
The consumers all pin v0.1.0 today, so nothing breaks until they upgrade. These places rely on
http://localhost:cmd/rypt/hardening_test.go:130, theLOCALHOST,LocalHostandlocalhostcases;internal/cli/roundtrip_test.go:338;README.md:98;scripts/probe.go:15-16and its lowercasing block at lines 77-80.internal/keys/provider/provider_test.go:130and:196.api.go:103. The plugin already enforces the same rule.This is a breaking change, so per CONTRIBUTING.md the next release would be a minor bump (v0.2.0).
🤖 Generated with Claude Code
https://claude.ai/code/session_01NYjhaGCRVp9GXLUuUZv8g1