[MEDIUM] Classify rooted IPs and bound hostname normalization - #41
Open
OskarEichler wants to merge 1 commit into
Open
[MEDIUM] Classify rooted IPs and bound hostname normalization#41OskarEichler wants to merge 1 commit into
OskarEichler wants to merge 1 commit into
Conversation
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 freeto 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.
Summary
Why
IP detection currently runs before the trailing root dot is removed. As a result,
127.0.0.1.becomes a domain object with registered domain0.1instead of an IP object. A caller that resolves or otherwise canonicalizes the rooted host can therefore apply domain-oriented policy to an IP address; the focused reproduction showed an HTTP cookie withDomain=.0.1being accepted for that origin.The Punycode encoder also does quadratic work on large inputs with many distinct code points. Invalid oversized IDN labels reached that work through
DomainName.new. The DNS limits stop such inputs before the expensive encode and validate the encoded result as well.Measured on Ruby 4.0.6 before this change, distinct-code-point labels took approximately 0.095s at 1,000 characters, 0.383s at 2,000, 1.52s at 4,000, and 6.09s at 8,000.
Verification
ruby -c lib/domain_name.rbandgit diff --checkpass.No test files were changed.
Compatibility
Breaking change: inputs outside the DNS 63-byte label and 253-byte hostname limits now raise
ArgumentError. Valid DNS names retain their existing normalized output.The lower-level
DomainName::PunycodeAPI remains available for non-hostname encoding; the bounds apply at theDomainNamehostname boundary.