You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2019/06/01 13:55:29 UTC

[httpcomponents-client] branch HTTPCLIENT-1991 created (now cacbc6b)

This is an automated email from the ASF dual-hosted git repository.

olegk pushed a change to branch HTTPCLIENT-1991
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git.


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

This branch includes the following new commits:

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

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[httpcomponents-client] 01/01: HTTPCLIENT-1991: incorrect handling of non-standard DNS entries by PublicSuffixMatcher

Posted by ol...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

olegk pushed a commit to branch HTTPCLIENT-1991
in repository https://gitbox.apache.org/repos/asf/httpcomponents-client.git

commit cacbc6b87fb30afb5e2e3f21f09a86ee2043133e
Author: Oleg Kalnichevski <ol...@apache.org>
AuthorDate: Sat Jun 1 15:43:24 2019 +0200

    HTTPCLIENT-1991: incorrect handling of non-standard DNS entries by PublicSuffixMatcher
---
 .../apache/http/conn/util/PublicSuffixMatcher.java | 22 ++++++++++------------
 .../http/conn/util/TestPublicSuffixListParser.java |  2 +-
 .../http/conn/util/TestPublicSuffixMatcher.java    |  4 ++--
 .../impl/cookie/TestPublicSuffixListParser.java    |  2 +-
 httpclient/src/test/resources/suffixlist.txt       |  1 +
 5 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/httpclient/src/main/java/org/apache/http/conn/util/PublicSuffixMatcher.java b/httpclient/src/main/java/org/apache/http/conn/util/PublicSuffixMatcher.java
index e069370..1793377 100644
--- a/httpclient/src/main/java/org/apache/http/conn/util/PublicSuffixMatcher.java
+++ b/httpclient/src/main/java/org/apache/http/conn/util/PublicSuffixMatcher.java
@@ -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;
     }
 
     /**
diff --git a/httpclient/src/test/java/org/apache/http/conn/util/TestPublicSuffixListParser.java b/httpclient/src/test/java/org/apache/http/conn/util/TestPublicSuffixListParser.java
index 35ac9d5..a1cb415 100644
--- a/httpclient/src/test/java/org/apache/http/conn/util/TestPublicSuffixListParser.java
+++ b/httpclient/src/test/java/org/apache/http/conn/util/TestPublicSuffixListParser.java
@@ -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());
     }
 
diff --git a/httpclient/src/test/java/org/apache/http/conn/util/TestPublicSuffixMatcher.java b/httpclient/src/test/java/org/apache/http/conn/util/TestPublicSuffixMatcher.java
index 8c124ff..cb986c0 100644
--- a/httpclient/src/test/java/org/apache/http/conn/util/TestPublicSuffixMatcher.java
+++ b/httpclient/src/test/java/org/apache/http/conn/util/TestPublicSuffixMatcher.java
@@ -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
diff --git a/httpclient/src/test/java/org/apache/http/impl/cookie/TestPublicSuffixListParser.java b/httpclient/src/test/java/org/apache/http/impl/cookie/TestPublicSuffixListParser.java
index 50816ba..49e3516 100644
--- a/httpclient/src/test/java/org/apache/http/impl/cookie/TestPublicSuffixListParser.java
+++ b/httpclient/src/test/java/org/apache/http/impl/cookie/TestPublicSuffixListParser.java
@@ -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
diff --git a/httpclient/src/test/resources/suffixlist.txt b/httpclient/src/test/resources/suffixlist.txt
index f5ff283..6aa880c 100644
--- a/httpclient/src/test/resources/suffixlist.txt
+++ b/httpclient/src/test/resources/suffixlist.txt
@@ -23,6 +23,7 @@
 // <http://www.apache.org/>.
 //
 
+xx
 jp
 ac.jp
 *.tokyo.jp