Skip to content

Reject malformed Host header ports#13050

Merged
bneradt merged 1 commit intoapache:masterfrom
bneradt:fix-host-port-parsing
Apr 3, 2026
Merged

Reject malformed Host header ports#13050
bneradt merged 1 commit intoapache:masterfrom
bneradt:fix-host-port-parsing

Conversation

@bneradt
Copy link
Copy Markdown
Contributor

@bneradt bneradt commented Apr 2, 2026

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

@bneradt bneradt added this to the 11.0.0 milestone Apr 2, 2026
@bneradt bneradt requested a review from Copilot April 2, 2026 01:50
@bneradt bneradt self-assigned this Apr 2, 2026
@bneradt bneradt force-pushed the fix-host-port-parsing branch from 8fe3d5a to 503bc41 Compare April 2, 2026 01:56
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/validate Host field 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_atoi parsing.
  • 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.

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
@bneradt bneradt force-pushed the fix-host-port-parsing branch from 503bc41 to 7fc34e4 Compare April 2, 2026 18:25
@bneradt bneradt merged commit de776b0 into apache:master Apr 3, 2026
15 checks passed
@bneradt bneradt deleted the fix-host-port-parsing branch April 3, 2026 14:44
@github-project-automation github-project-automation bot moved this to For v10.2.0 in ATS v10.2.x Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: For v10.2.0

Development

Successfully merging this pull request may close these issues.

URLImpl::set_port buffer overflow

3 participants