Skip to content

Commit eae3944

Browse files
Alex Klyubinandi34
authored andcommitted
Fix a bug in OkHostnameVerifier wildcard handling.
Wildcard domain name patterns of the form *.remainder are supposed to match domain names that exactly match the remainder. Due to a bug, the match was not exact but rather a prefix match: domain names starting with the remainder would match too. This CL fixes the issue. (cherry picked from commit a03ec4ced2b11f9eae6cbeeedb1db2b1b29fafb1) Bug: 18432707 Change-Id: Ie40b71a26df1ac2a972341e7b3b40dd9cf38e8b1
1 parent b6b72da commit eae3944

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/main/java/com/squareup/okhttp/internal/tls/OkHostnameVerifier.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public boolean verifyHostName(String hostName, String cn) {
162162
return hostName.equals(cn);
163163
}
164164

165-
if (cn.startsWith("*.") && hostName.regionMatches(0, cn, 2, cn.length() - 2)) {
165+
if (cn.startsWith("*.") && hostName.equals(cn.substring(2))) {
166166
return true; // "*.foo.com" matches "foo.com"
167167
}
168168

src/test/java/com/squareup/okhttp/internal/tls/HostnameVerifierTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ public final class HostnameVerifierTest {
293293
assertTrue(verifier.verify("www.foo.com", session));
294294
assertTrue(verifier.verify("\u82b1\u5b50.foo.com", session));
295295
assertFalse(verifier.verify("a.b.foo.com", session));
296+
assertFalse(verifier.verify("foo.com.au", session));
296297
}
297298

298299
@Test public void verifyWilcardCnOnTld() throws Exception {

0 commit comments

Comments
 (0)