HTTPCLIENT-1991: incorrect handling of non-standard DNS entries by PublicSuffixMatcher

This commit is contained in:
Oleg Kalnichevski 2019-06-01 15:43:24 +02:00
parent e605ca0500
commit cacbc6b87f
5 changed files with 15 additions and 16 deletions

View File

@ -142,17 +142,17 @@ public final class PublicSuffixMatcher {
if (domain.startsWith(".")) {
return null;
}
String domainName = null;
String segment = domain.toLowerCase(Locale.ROOT);
final String normalized = domain.toLowerCase(Locale.ROOT);
String segment = normalized;
String result = null;
while (segment != null) {
// An exception rule takes priority over any other matching rule.
if (hasException(IDN.toUnicode(segment), expectedType)) {
final String key = IDN.toUnicode(segment);
if (hasException(key, expectedType)) {
return segment;
}
if (hasRule(IDN.toUnicode(segment), expectedType)) {
break;
if (hasRule(key, expectedType)) {
return result;
}
final int nextdot = segment.indexOf('.');
@ -160,15 +160,13 @@ public final class PublicSuffixMatcher {
if (nextSegment != null) {
if (hasRule("*." + IDN.toUnicode(nextSegment), expectedType)) {
break;
return result;
}
}
if (nextdot != -1) {
domainName = segment;
}
result = segment;
segment = nextSegment;
}
return domainName;
return normalized;
}
/**

View File

@ -52,7 +52,7 @@ public class TestPublicSuffixListParser {
in.close();
}
Assert.assertNotNull(suffixList);
Assert.assertEquals(Arrays.asList("jp", "ac.jp", "*.tokyo.jp", "no", "h\u00E5.no"), suffixList.getRules());
Assert.assertEquals(Arrays.asList("xx", "jp", "ac.jp", "*.tokyo.jp", "no", "h\u00E5.no"), suffixList.getRules());
Assert.assertEquals(Arrays.asList("metro.tokyo.jp"), suffixList.getExceptions());
}

View File

@ -63,13 +63,13 @@ public class TestPublicSuffixMatcher {
Assert.assertEquals("example.xx", matcher.getDomainRoot("www.blah.blah.example.XX"));
Assert.assertEquals(null, matcher.getDomainRoot("xx"));
Assert.assertEquals(null, matcher.getDomainRoot("jp"));
Assert.assertEquals(null, matcher.getDomainRoot("example"));
Assert.assertEquals("example.example", matcher.getDomainRoot("example.example"));
Assert.assertEquals(null, matcher.getDomainRoot("ac.jp"));
Assert.assertEquals(null, matcher.getDomainRoot("any.tokyo.jp"));
Assert.assertEquals("metro.tokyo.jp", matcher.getDomainRoot("metro.tokyo.jp"));
Assert.assertEquals("blah.blah.tokyo.jp", matcher.getDomainRoot("blah.blah.tokyo.jp"));
Assert.assertEquals("blah.ac.jp", matcher.getDomainRoot("blah.blah.ac.jp"));
Assert.assertEquals("garbage", matcher.getDomainRoot("garbage"));
Assert.assertEquals("garbage.garbage", matcher.getDomainRoot("garbage.garbage"));
}
@Test

View File

@ -101,7 +101,7 @@ public class TestPublicSuffixListParser {
Assert.assertTrue(filter.match(cookie, new CookieOrigin("somehost.local", 80, "/stuff", false)));
cookie.setDomain(".blah");
Assert.assertFalse(filter.match(cookie, new CookieOrigin("somehost.blah", 80, "/stuff", false)));
Assert.assertTrue(filter.match(cookie, new CookieOrigin("somehost.blah", 80, "/stuff", false)));
}
@Test

View File

@ -23,6 +23,7 @@
// <http://www.apache.org/>.
//
xx
jp
ac.jp
*.tokyo.jp