Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,15 @@ public Handler matchAndApply(Handler input) throws IOException
if (virtualHost == null || virtualHost.equalsIgnoreCase(serverName))
return super.matchAndApply(input);

// Handle case-insensitive wildcard host names.
if (virtualHost.startsWith("*.") &&
virtualHost.regionMatches(true, 2, serverName, serverName.indexOf(".") + 1, virtualHost.length() - 2))
return super.matchAndApply(input);
// Handle case-insensitive wildcard host names, which match exactly one level.
if (virtualHost.startsWith("*.") && serverName != null)
{
int domain = serverName.indexOf('.') + 1;
int domainLength = serverName.length() - domain;
if (domain > 0 && domainLength == virtualHost.length() - 2 &&
virtualHost.regionMatches(true, 2, serverName, domain, domainLength))
return super.matchAndApply(input);
}
}

// No virtual host match, skip the other rules.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ public void testWildcardVirtualHosts() throws Exception
testWildcardVirtualHost(true, List.of("*.sub.foo.com"), List.of("vhost.sub.foo.com", ".sub.foo.com"));
testWildcardVirtualHost(false, List.of("*.sub.foo.com"), List.of(".foo.com", "sub.foo.com", "vhost.foo.com"));
testWildcardVirtualHost(false, List.of("foo.*.com", "foo.com.*"), List.of("foo.vhost.com", "foo.com.vhost", "foo.com"));
testWildcardVirtualHost(false, List.of("*.foo.com"), List.of("vhost.foo.com.evil.com", "vhost.foo.comevil.com"));
}

private void testWildcardVirtualHost(boolean succeed, List<String> ruleHosts, List<String> requestHosts) throws Exception
Expand Down
Loading