fix: normalize the case of hosts carried on a service - #13781
Merged
Conversation
Hostnames are case-insensitive and are matched against `$host`, which nginx always lowercases. `apisix/router.lua` lowercases route-level hosts, but service-level hosts were stored verbatim, and `radixtree_host_uri` buckets routes by the raw reversed host string. A service host containing an uppercase character therefore landed in a bucket no request could ever reach, and every request for that host returned 404. `radixtree_uri` was not affected: lua-resty-radixtree lowercases hosts on both the config and the request side.
shreemaan-abhishek
approved these changes
Aug 6, 2026
nic-6443
approved these changes
Aug 7, 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.
Description
Hostnames are case-insensitive, and route matching runs against
$host, which nginx always lowercases (ngx_http_validate_host()).apisix/router.luanormalizes this on the route object:apisix/http/service.luahas no equivalent, soservice.hostsis stored verbatim.radixtree_host_uri— the default router — builds its host buckets itself, keyed on the raw reversed host string:A service host containing an uppercase character therefore ends up in a bucket keyed on e.g.
moc.elpmaxe.esaCdexiM, which the lowercase$hostcan never reach. The route falls through toonly_uri_router, and if nothing host-agnostic matches, the request 404s — for every path and every casing of the requestHost, so the host is silently unroutable.radixtree_uriis not affected, because it passeshoststo lua-resty-radixtree, which lowercases on both the config side and the request side.Reproduced on 3.16.0 in standalone mode, with
service.hosts: ["MixedCase.example.com"]and a route with nohostsof its own:Hostradixtree_host_uri(default)radixtree_uriMixedCase.example.commixedcase.example.comMIXEDCASE.EXAMPLE.COMThis patch lowercases the hosts in the service
filter(), mirroring whatrouter.luaalready does for routes.The new
t/router/radixtree-host-uri3.tTEST 10 covers it — its functional assertions pass with the patch and fail without it:Found via apache/apisix-ingress-controller#2822: the controller carries the host constraint on the service object, so an ingress route with an uppercase hostname is unroutable.
Which issue(s) this PR fixes:
N/A
Checklist