Skip to content

fix(ingress): match hostnames case-insensitively (RFC 4343) - #1716

Open
winklemad wants to merge 1 commit into
cloudflare:masterfrom
winklemad:fix/ingress-case-insensitive-host
Open

fix(ingress): match hostnames case-insensitively (RFC 4343)#1716
winklemad wants to merge 1 commit into
cloudflare:masterfrom
winklemad:fix/ingress-case-insensitive-host

Conversation

@winklemad

Copy link
Copy Markdown

Fixes #1715.

Ingress rule matching was case-sensitive, but hostnames are case-insensitive (RFC 4343; RFC 3986 §3.2.2). matchHost compared with == / strings.HasSuffix without normalizing case, and validateHostname accepts mixed-case hostnames — so a config like hostname: MyApp.example.com, or any mixed-case request Host reaching proxy.go, would skip the intended rule and fall through to the catch-all.

This lower-cases both sides in matchHost, matching how every other HTTP router (nginx, Caddy, Envoy, Traefik) treats hostnames.

Adds TestMatchHostCaseInsensitive (direct) and TestFindMatchingRuleCaseInsensitive (end-to-end); both fail on main and pass with the fix. go test ./ingress/ and go vet ./ingress/ are clean.

matchHost compared hostnames with == / strings.HasSuffix without
normalizing case, but hostnames are case-insensitive (RFC 4343, RFC 3986
3.2.2). validateHostname accepts mixed-case hostnames, and req.Host reaches
matching un-lowercased, so a mixed-case Host or config hostname would skip
the intended rule and fall through to the catch-all. Lower-case both sides;
add direct + end-to-end tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(ingress): host matching is case-sensitive, mixed-case Host/hostname misroutes (RFC 4343)

1 participant