Skip to content

Commit 75425ad

Browse files
namedgraphclaude
andcommitted
Restrict subdomain preservation to same-domain proxy configs
The previous fix unconditionally prepended the subdomain prefix to proxyHost, which broke dev setups using an internal proxy hostname (e.g. PROXY_HOST=nginx): admin.localhost was rewritten to admin.nginx instead of nginx, which doesn't resolve in Docker. Only preserve the subdomain when proxyHost equals host (the production case where both are the same domain). In that case the HTTP client would otherwise reuse an existing connection with SNI=host for the subdomain request, causing nginx to return 421 Misdirected Request. Update test to reflect the correct behaviour for the internal-proxy case. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent bfed8ec commit 75425ad

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

src/main/java/com/atomgraph/linkeddatahub/client/filter/ClientUriRewriteFilter.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,11 @@ public void filter(ClientRequestContext cr) throws IOException
7070
String newScheme = cr.getUri().getScheme();
7171
if (getProxyScheme() != null) newScheme = getProxyScheme();
7272

73-
// Preserve subdomain prefix to avoid HTTP client connection pool conflating subdomain and base domain connections
73+
// Preserve subdomain prefix only when proxyHost is the same domain as host, to prevent
74+
// the HTTP client reusing a connection with a different TLS SNI (which causes 421).
75+
// When proxyHost is a distinct internal hostname (e.g. "nginx"), no collision is possible.
7476
String newHost = getProxyHost();
75-
if (cr.getUri().getHost().endsWith("." + getHost()))
77+
if (cr.getUri().getHost().endsWith("." + getHost()) && getProxyHost().equals(getHost()))
7678
{
7779
String subdomainPrefix = cr.getUri().getHost().substring(0, cr.getUri().getHost().length() - getHost().length()); // e.g. "admin."
7880
newHost = subdomainPrefix + getProxyHost();

src/test/java/com/atomgraph/linkeddatahub/client/filter/ClientUriRewriteFilterTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,16 @@ public void testRewriteSubdomainPreservesSubdomainWithSameDomainProxy() throws I
135135

136136
/**
137137
* Subdomain match with internal proxy host (Docker Compose setup):
138-
* subdomain prefix is prepended to the proxy hostname for nginx virtual-host routing.
138+
* subdomain prefix must NOT be prepended to the proxy hostname — the internal
139+
* hostname (e.g. "nginx") has no subdomain equivalent. nginx routes via Host header.
139140
*/
140141
@Test
141-
public void testRewriteSubdomainPreservesSubdomainWithInternalProxy() throws IOException
142+
public void testRewriteSubdomainWithInternalProxyUsesProxyHostOnly() throws IOException
142143
{
143144
ClientUriRewriteFilter filter = new ClientUriRewriteFilter("example.com", "http", "nginx", 9443);
144145
StubRequestContext ctx = new StubRequestContext(URI.create("https://admin.example.com/path"));
145146
filter.filter(ctx);
146-
assertEquals(URI.create("http://admin.nginx:9443/path"), ctx.getUri());
147+
assertEquals(URI.create("http://nginx:9443/path"), ctx.getUri());
147148
assertEquals("admin.example.com", ctx.getHeaders().getFirst("Host"));
148149
}
149150

0 commit comments

Comments
 (0)