Repository navigation
Conversation
…r.localhost() OriginValidator.localhost() builds wildcard patterns such as "localhost:*", and matchesPattern required a ":<digits>" suffix. A request whose Host is "localhost" (or Origin "http://localhost") was rejected with 421/403, even though a missing port means the scheme's default port (RFC 9110, section 7.2). That breaks a server bound to port 80 on its own loopback requests. The wildcard now also matches the bare host. Port-specific validators (localhost(port:)) are unchanged, and non-loopback hosts are still rejected. Adds OriginValidatorTests, covering accepted loopback forms, rejected hosts and origins, and the port-specific validator. AI assistance: the change and tests were drafted with an AI coding assistant.
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.
OriginValidator.localhost()builds wildcard patterns such aslocalhost:*, andmatchesPatternrequires a:<digits>suffix after the host. A request withHost: localhost(orOrigin: http://localhost) is therefore rejected with 421/403. A missing port means the scheme's default port (RFC 9110, section 7.2), so a server bound to port 80 rejects its own loopback requests.This change makes the wildcard also match the bare host.
localhost(port:)is unchanged, and non-loopback hosts are still rejected.Tests: adds
OriginValidatorTests, covering accepted loopback forms with and without a port, rejected hosts and origins, and the port-specific validator. There were no tests forOriginValidatorbefore.swift buildandswift teston Linux (Swift 6.1.2,swift:6.1.2-noble): 500 tests passed.localhost,127.0.0.1,[::1]andhttp://localhost.AI assistance: the change and tests were drafted with an AI coding assistant and reviewed by a person before submitting.