Netty: CorsHandler omits Vary: Origin for the null-origin branch, unlike every other origin-matching path
Description
CorsHandler's response-origin logic has three branches that decide what Access-Control-Allow-Origin value to emit based on the incoming request's Origin header. Two of the three branches call the Vary-header helper immediately after setting an origin-dependent value — the mechanism that stops shared caches from conflating responses computed for different Origins. The third branch, which handles the special literal "null" Origin (a supported, documented, opt-in configuration), sets Access-Control-Allow-Origin: null and returns without ever adding Vary: Origin. A shared cache in front of a service using this configuration can key/serve the null-origin response purely by URL and hand it to unrelated clients with different Origins.
Details
setOrigin(HttpResponse) (codec-http/src/main/java/io/netty/handler/codec/http/cors/CorsHandler.java, lines 165-189):
private boolean setOrigin(final HttpResponse response) { final String origin = request.headers().get(HttpHeaderNames.ORIGIN); if (origin != null && config != null) { if (NULL_ORIGIN.equals(origin) && config.isNullOriginAllowed()) { setNullOrigin(response); return true; // no setVaryHeader() call here } if (config.isAnyOriginSupported()) { if (config.isCredentialsAllowed()) { echoRequestOrigin(response); setVaryHeader(response); // present } else { setAnyOrigin(response); } return true; } if (config.origins().contains(origin)) { setOrigin(response, origin); setVaryHeader(response); // present return true; } } return false; }
setNullOrigin (lines 205-207) is just setOrigin(response, NULL_ORIGIN) — no Vary logic anywhere in that path. This method is shared by both the simple-response path (write(), line 260) and the preflight path (handlePreflight(), line 125), so both are affected.
The ACAO value genuinely differs by Origin for the identical URL under a supported, unit-tested configuration — CorsConfigBuilder.forOrigin(x).allowNullOrigin(), used to let sandboxed/file://-origin or Electron-style clients access an API alongside a normal web origin — so omitting Vary here is a real caching-correctness bug, not a hypothetical one.
CorsHandlerTest.java corroborates this: every other preflight/simple-response test asserts the Vary header (lines 132, 148, 158, 169, 193, 207, 222, 289), but the two tests that specifically exercise the null-origin path — simpleRequestWithNullOrigin (line 78) and preflightRequestWithNullOrigin (line 227) — contain no VARY assertion at all.
This is not the same bug as the recently-fixed CVE-2026-59903: that CVE was about setVaryHeader() using .set() and silently overwriting an application's own pre-existing Vary header (e.g. Vary: Cookie); the fix changed it to check-then-add(). That fix did not touch the null-origin branch and did not add a setVaryHeader() call there — this gap was left behind by that fix, not addressed by it.
PoC
Compiled a standalone Java harness against the actual, unmodified, freshly-cloned CorsHandler/CorsConfig source and ran it through EmbeddedChannel using CorsConfigBuilder.forOrigin("https://app.example.com").allowNullOrigin().allowCredentials().build() — the exact configuration pattern from the project's own tests:
Origin: null→ response hasAccess-Control-Allow-Origin: null,Access-Control-Allow-Credentials: true, Vary absentOrigin: https://app.example.com(same handler, same config, same URL) →Access-Control-Allow-Origin: https://app.example.com,Access-Control-Allow-Credentials: true, Vary: origin present
Same divergence reproduced for both the simple-response path and the preflight OPTIONS path — proving the response genuinely differs by Origin while only one of the two possible shapes advertises that via Vary.
Real-world trigger: a Netty HTTP service configured with CorsConfigBuilder.forOrigin("https://app.example.com").allowNullOrigin().allowCredentials().build() sits behind a shared cache/CDN/reverse proxy (Varnish, nginx proxy_cache, CloudFront, Cloudflare, corporate forward proxy) that caches a cacheable GET endpoint and honors Vary. An attacker (a sandboxed iframe, a file://-origin/data: document, or simply a raw HTTP client — trivial to spoof, no browser trust boundary needed) sends a request to the cached URL with Origin: null. The intermediary cache stores the null-origin-flavored response keyed only by URL, since it was never told the response varies by Origin. Any subsequent request to the same URL through that cache — including from the legitimate https://app.example.com origin — receives the stale, poisoned response with the wrong ACAO/ACAC pairing.
Impact
Breaks CORS access-control expectations for the legitimate origin (their fetch()/XHR gets blocked by the browser due to an ACAO mismatch against a stale cached value), and whenever the endpoint's response body genuinely varies by session/Origin and the deployment lacks independent cookie-based cache isolation, discloses one requester's cached response to a completely different origin/user.
This requires the non-default, opt-in allowNullOrigin() configuration to be reachable and a Vary-respecting shared cache in front — a real but narrower precondition than the sibling CVE, reflected in the lower score below.
Suggested fix: call setVaryHeader(response) in the null-origin branch too, matching the other two branches in the same method.