fix: reject hostnames exceeding 253 characters#445
Open
Jo2234 wants to merge 1 commit intopython-validators:masterfrom
Open
fix: reject hostnames exceeding 253 characters#445Jo2234 wants to merge 1 commit intopython-validators:masterfrom
Jo2234 wants to merge 1 commit intopython-validators:masterfrom
Conversation
Per RFC 1123, a hostname must not exceed 253 characters. The existing validator only checked individual label length (≤63 chars via regex) but never validated the total hostname length. This allowed hostnames with multiple short labels separated by dots to pass validation even when the total length exceeded 253 characters. The fix adds an early length check after stripping port and IPv6 brackets, before proceeding with label/domain/IP validation. Fixes python-validators#413
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.
Summary
Add RFC 1123 conformant total hostname length validation. Hostnames exceeding 253 characters are now correctly rejected.
Problem
The existing hostname validator checked individual label length (≤63 chars via regex) but never validated the total hostname length. Per RFC 1123, a hostname must not exceed 253 characters.
Fix
Added an early length check in
hostname()that:This runs before the existing label/domain/IP validation.
Fixes #413