Fix HTTP/2 coalescing cross-routing in targetinfo.lua
Hosts that share one wildcard cert (e.g. hassio.718it.biz and metrics.718it.biz under *.718it.biz) resolve to the same IP, so browsers coalesce them onto a single HTTP/2 connection. The SSL request_domain phase resolves the connection's first host and caches it in ngx.ctx.targetInfo; the unguarded `if targetInfo then return targetInfo` then handed that first host's target to every coalesced request on the connection -- e.g. hassio.718it.biz served from metrics' 192.168.1.8:8088. Confirmed via debug logging: for GET requests to hassio.718it.biz on a coalesced connection, ngx.ctx already held metrics' IP and the function short-circuited to it. Guard the reuse by host: only return the cached target when ngx.ctx.targetInfo_domain matches the requested domain, and record that domain whenever a target is resolved. A coalesced request for a different host now re-resolves against its actual Host header. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -13,7 +13,14 @@ print("In targetInfo module")
|
|||||||
|
|
||||||
-- Main function of the module
|
-- Main function of the module
|
||||||
function M.get(ngx, domain, targetInfo)
|
function M.get(ngx, domain, targetInfo)
|
||||||
if targetInfo then
|
-- Reuse a previously-resolved target ONLY when it was resolved for this
|
||||||
|
-- exact host. HTTP/2 connection coalescing lets a browser serve several
|
||||||
|
-- hostnames that share one wildcard cert (e.g. *.718it.biz) over a single
|
||||||
|
-- connection; the SSL phase (request_domain) resolves and caches the
|
||||||
|
-- connection's first host in ngx.ctx.targetInfo. Without the domain check
|
||||||
|
-- below, every coalesced request on that connection would be handed the
|
||||||
|
-- first host's target -- e.g. hassio.718it.biz served from metrics.718it.biz.
|
||||||
|
if targetInfo and ngx.ctx.targetInfo_domain == domain then
|
||||||
return targetInfo
|
return targetInfo
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -68,6 +75,10 @@ function M.get(ngx, domain, targetInfo)
|
|||||||
end
|
end
|
||||||
|
|
||||||
ngx.ctx.targetInfo = res
|
ngx.ctx.targetInfo = res
|
||||||
|
-- Remember which host this target was resolved for, so the reuse guard at
|
||||||
|
-- the top can tell a genuine cache hit from a coalesced request for a
|
||||||
|
-- different host on the same connection.
|
||||||
|
ngx.ctx.targetInfo_domain = domain
|
||||||
ngx.ctx.toAllow = true
|
ngx.ctx.toAllow = true
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|||||||
Reference in New Issue
Block a user