Reject malformed Host header ports#13050
Merged
bneradt merged 1 commit intoapache:masterfrom Apr 3, 2026
Merged
Conversation
8fe3d5a to
503bc41
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens ATS Host header handling to prevent malformed authorities (notably multiple-colon “ports”) from being reused as request targets or cached host state, addressing the reported URLImpl::set_port() overflow vector.
Changes:
- Added
http_parse_host_header()to parse/validateHostfield values (host or host:port, IPv6 bracket rules, strict numeric port range). - Updated several call sites to rely on the new parser instead of ad-hoc
:splitting /ink_atoiparsing. - Added regression coverage via a new gold replay test and new Catch2 unit tests around Host parsing and promotion behavior.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/gold_tests/headers/replays/malformed_host_port.replay.yaml | New replay intended to assert ATS rejects Host values with multiple port separators. |
| tests/gold_tests/headers/malformed_host_port.test.py | New gold test wrapper executing the replay. |
| src/proxy/http/remap/UrlRewrite.cc | Uses http_parse_host_header() when deriving host/port from Host for redirect mapping. |
| src/proxy/http/HttpTransact.cc | Uses http_parse_host_header() to safely populate pristine host/port into cache lookup URL. |
| src/proxy/http/HttpSM.cc | Uses http_parse_host_header() when extracting host/port for unmapped_url during remap. |
| src/proxy/hdrs/unit_tests/test_Hdrs.cc | Adds unit tests for http_parse_host_header() and Host validation/promotion behaviors. |
| src/proxy/hdrs/HTTP.cc | Implements http_parse_host_header() and rewires Host validation + Host cache fill logic to use it. |
| include/proxy/hdrs/HTTP.h | Declares http_parse_host_header() and documents Host validation behavior. |
tests/gold_tests/headers/replays/malformed_host_port.replay.yaml
Outdated
Show resolved
Hide resolved
Reject malformed Host field authorities before ATS reuses them as request targets or cached host state. Shared Host parsing now requires host or host:port syntax, enforces bracketed IPv6 when a port is present, and rejects invalid or out-of-range ports. This patch adds http_parse_host_header, a new host parser function which also validates the required host header format. The patch also updates the various host header parsing logic blocks across ATS to use the new parser. Reported-by: Ankit Fixes: apache#13049
503bc41 to
7fc34e4
Compare
maskit
approved these changes
Apr 2, 2026
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.
Reject malformed Host field authorities before ATS reuses them as request targets or cached host state. Shared Host parsing now requires host or host:port syntax, enforces bracketed IPv6 when a port is present, and rejects invalid or out-of-range ports.
This patch adds http_parse_host_header, a new host parser function which also validates the required host header format. The patch also updates the various host header parsing logic blocks across ATS to use the new parser.
Reported-by: Ankit Singh
Fixes: #13049