- Revision
- 228086
- Author
- carlo...@webkit.org
- Date
- 2018-02-05 00:04:30 -0800 (Mon, 05 Feb 2018)
Log Message
Add a way to check if a host is an IP address
https://bugs.webkit.org/show_bug.cgi?id=182427
Reviewed by Alex Christensen.
Source/WebCore:
There are several places where this is needed. We currently just assume that any host ending in a digit is an IP
address, except in PublicSuffix where platform specific code is used. This patch adds URL::hostIsIPAddress()
platform specific implementations, falling back to current assumption if there isn't an implementation for the
platform.
* page/OriginAccessEntry.cpp:
(WebCore::OriginAccessEntry::OriginAccessEntry): Use URL::hostIsIPAddress().
* platform/URL.cpp:
(WebCore::URL::hostIsIPAddress): Fallback implementation.
* platform/URL.h:
* platform/mac/PublicSuffixMac.mm:
(WebCore::topPrivatelyControlledDomain): Use URL::hostIsIPAddress().
* platform/mac/URLMac.mm:
(WebCore::URL::hostIsIPAddress): Move implementation from PublicSuffixMac.mm.
* platform/network/curl/CookieUtil.cpp:
(WebCore::CookieUtil::isIPAddress): Use URL::hostIsIPAddress().
* platform/soup/URLSoup.cpp:
(WebCore::URL::hostIsIPAddress): Use g_hostname_is_ip_address().
Tools:
Add unit test for URL::hostIsIPAddress().
* TestWebKitAPI/Tests/WebCore/URL.cpp:
(TestWebKitAPI::TEST_F):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (228085 => 228086)
--- trunk/Source/WebCore/ChangeLog 2018-02-05 07:38:08 UTC (rev 228085)
+++ trunk/Source/WebCore/ChangeLog 2018-02-05 08:04:30 UTC (rev 228086)
@@ -1,3 +1,29 @@
+2018-02-05 Carlos Garcia Campos <cgar...@igalia.com>
+
+ Add a way to check if a host is an IP address
+ https://bugs.webkit.org/show_bug.cgi?id=182427
+
+ Reviewed by Alex Christensen.
+
+ There are several places where this is needed. We currently just assume that any host ending in a digit is an IP
+ address, except in PublicSuffix where platform specific code is used. This patch adds URL::hostIsIPAddress()
+ platform specific implementations, falling back to current assumption if there isn't an implementation for the
+ platform.
+
+ * page/OriginAccessEntry.cpp:
+ (WebCore::OriginAccessEntry::OriginAccessEntry): Use URL::hostIsIPAddress().
+ * platform/URL.cpp:
+ (WebCore::URL::hostIsIPAddress): Fallback implementation.
+ * platform/URL.h:
+ * platform/mac/PublicSuffixMac.mm:
+ (WebCore::topPrivatelyControlledDomain): Use URL::hostIsIPAddress().
+ * platform/mac/URLMac.mm:
+ (WebCore::URL::hostIsIPAddress): Move implementation from PublicSuffixMac.mm.
+ * platform/network/curl/CookieUtil.cpp:
+ (WebCore::CookieUtil::isIPAddress): Use URL::hostIsIPAddress().
+ * platform/soup/URLSoup.cpp:
+ (WebCore::URL::hostIsIPAddress): Use g_hostname_is_ip_address().
+
2018-02-04 Zan Dobersek <zdober...@igalia.com>
[Cairo] Correctly calculate stride in GraphicsContext3D::paintToCanvas()
Modified: trunk/Source/WebCore/page/OriginAccessEntry.cpp (228085 => 228086)
--- trunk/Source/WebCore/page/OriginAccessEntry.cpp 2018-02-05 07:38:08 UTC (rev 228085)
+++ trunk/Source/WebCore/page/OriginAccessEntry.cpp 2018-02-05 08:04:30 UTC (rev 228086)
@@ -40,11 +40,9 @@
, m_host(host.convertToASCIILowercase())
, m_subdomainSettings(subdomainSetting)
, m_ipAddressSettings(ipAddressSetting)
+ , m_hostIsIPAddress(URL::hostIsIPAddress(m_host))
{
ASSERT(subdomainSetting == AllowSubdomains || subdomainSetting == DisallowSubdomains);
-
- // Assume that any host that ends with a digit is trying to be an IP address.
- m_hostIsIPAddress = !m_host.isEmpty() && isASCIIDigit(m_host[m_host.length() - 1]);
}
bool OriginAccessEntry::matchesOrigin(const SecurityOrigin& origin) const
@@ -69,7 +67,7 @@
// IP addresses are not domains: https://url.spec.whatwg.org/#concept-domain
// Don't try to do subdomain matching on IP addresses.
- if (m_hostIsIPAddress && m_ipAddressSettings == TreatIPAddressAsIPAddress)
+ if (m_ipAddressSettings == TreatIPAddressAsIPAddress && (m_hostIsIPAddress || URL::hostIsIPAddress(origin.host())))
return false;
// Match subdomains.
Modified: trunk/Source/WebCore/platform/URL.cpp (228085 => 228086)
--- trunk/Source/WebCore/platform/URL.cpp 2018-02-05 07:38:08 UTC (rev 228085)
+++ trunk/Source/WebCore/platform/URL.cpp 2018-02-05 08:04:30 UTC (rev 228086)
@@ -1035,4 +1035,12 @@
return ts;
}
+#if !PLATFORM(COCOA) && !USE(SOUP)
+bool URL::hostIsIPAddress(const String& host)
+{
+ // Assume that any host that ends with a digit is trying to be an IP address.
+ return !host.isEmpty() && isASCIIDigit(host[host.length() - 1]);
+}
+#endif
+
} // namespace WebCore
Modified: trunk/Source/WebCore/platform/URL.h (228085 => 228086)
--- trunk/Source/WebCore/platform/URL.h 2018-02-05 07:38:08 UTC (rev 228085)
+++ trunk/Source/WebCore/platform/URL.h 2018-02-05 08:04:30 UTC (rev 228086)
@@ -175,6 +175,8 @@
unsigned hostStart() const;
unsigned hostEnd() const;
+ WEBCORE_EXPORT static bool hostIsIPAddress(const String&);
+
unsigned pathStart() const;
unsigned pathEnd() const;
unsigned pathAfterLastSlash() const;
Modified: trunk/Source/WebCore/platform/mac/PublicSuffixMac.mm (228085 => 228086)
--- trunk/Source/WebCore/platform/mac/PublicSuffixMac.mm 2018-02-05 07:38:08 UTC (rev 228085)
+++ trunk/Source/WebCore/platform/mac/PublicSuffixMac.mm 2018-02-05 08:04:30 UTC (rev 228086)
@@ -28,13 +28,9 @@
#if ENABLE(PUBLIC_SUFFIX_LIST)
-#import "WebCoreNSURLExtras.h"
+#import "URL.h"
#import <pal/spi/cf/CFNetworkSPI.h>
-@interface NSString (WebCoreNSURLExtras)
-- (BOOL)_web_looksLikeIPAddress;
-@end
-
namespace WebCore {
bool isPublicSuffix(const String& domain)
@@ -45,7 +41,7 @@
String topPrivatelyControlledDomain(const String& domain)
{
- if ([domain _web_looksLikeIPAddress])
+ if (URL::hostIsIPAddress(domain))
return domain;
if (!domain.isAllASCII())
Modified: trunk/Source/WebCore/platform/mac/URLMac.mm (228085 => 228086)
--- trunk/Source/WebCore/platform/mac/URLMac.mm 2018-02-05 07:38:08 UTC (rev 228085)
+++ trunk/Source/WebCore/platform/mac/URLMac.mm 2018-02-05 08:04:30 UTC (rev 228086)
@@ -28,9 +28,14 @@
#import "CFURLExtras.h"
#import "URLParser.h"
+#import "WebCoreNSURLExtras.h"
#import <wtf/ObjcRuntimeExtras.h>
#import <wtf/text/CString.h>
+@interface NSString (WebCoreNSURLExtras)
+- (BOOL)_web_looksLikeIPAddress;
+@end
+
namespace WebCore {
URL::URL(NSURL *url)
@@ -74,4 +79,9 @@
return createCFURLFromBuffer(buffer.data(), buffer.size());
}
+bool URL::hostIsIPAddress(const String& host)
+{
+ return [host _web_looksLikeIPAddress];
}
+
+}
Modified: trunk/Source/WebCore/platform/network/curl/CookieUtil.cpp (228085 => 228086)
--- trunk/Source/WebCore/platform/network/curl/CookieUtil.cpp 2018-02-05 07:38:08 UTC (rev 228085)
+++ trunk/Source/WebCore/platform/network/curl/CookieUtil.cpp 2018-02-05 08:04:30 UTC (rev 228086)
@@ -53,8 +53,7 @@
bool isIPAddress(const String& hostname)
{
- // Assuming that hosts ending in a digit are IP Addresses
- return !hostname.isEmpty() && isASCIIDigit(hostname[hostname.length() - 1]);
+ return URL::hostIsIPAddress(hostname);
}
bool domainMatch(const String& cookieDomain, const String& host)
Modified: trunk/Source/WebCore/platform/soup/URLSoup.cpp (228085 => 228086)
--- trunk/Source/WebCore/platform/soup/URLSoup.cpp 2018-02-05 07:38:08 UTC (rev 228085)
+++ trunk/Source/WebCore/platform/soup/URLSoup.cpp 2018-02-05 08:04:30 UTC (rev 228086)
@@ -66,6 +66,11 @@
return GUniquePtr<SoupURI>(soup_uri_new(string().utf8().data()));
}
+bool URL::hostIsIPAddress(const String& host)
+{
+ return !host.isEmpty() && g_hostname_is_ip_address(host.utf8().data());
+}
+
} // namespace WebCore
#endif
Modified: trunk/Tools/ChangeLog (228085 => 228086)
--- trunk/Tools/ChangeLog 2018-02-05 07:38:08 UTC (rev 228085)
+++ trunk/Tools/ChangeLog 2018-02-05 08:04:30 UTC (rev 228086)
@@ -1,3 +1,15 @@
+2018-02-05 Carlos Garcia Campos <cgar...@igalia.com>
+
+ Add a way to check if a host is an IP address
+ https://bugs.webkit.org/show_bug.cgi?id=182427
+
+ Reviewed by Alex Christensen.
+
+ Add unit test for URL::hostIsIPAddress().
+
+ * TestWebKitAPI/Tests/WebCore/URL.cpp:
+ (TestWebKitAPI::TEST_F):
+
2018-02-03 Charlie Turner <ctur...@igalia.com>
Add libmount to WPE dependencies
Modified: trunk/Tools/TestWebKitAPI/Tests/WebCore/URL.cpp (228085 => 228086)
--- trunk/Tools/TestWebKitAPI/Tests/WebCore/URL.cpp 2018-02-05 07:38:08 UTC (rev 228085)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/URL.cpp 2018-02-05 08:04:30 UTC (rev 228086)
@@ -231,4 +231,34 @@
EXPECT_TRUE(protocolIsInHTTPFamily("https://!@#$%^&*()"));
}
+TEST_F(URLTest, HostIsIPAddress)
+{
+ EXPECT_FALSE(URL::hostIsIPAddress({ }));
+ EXPECT_FALSE(URL::hostIsIPAddress(""));
+ EXPECT_FALSE(URL::hostIsIPAddress("localhost"));
+ EXPECT_FALSE(URL::hostIsIPAddress("127.localhost"));
+ EXPECT_FALSE(URL::hostIsIPAddress("localhost.127"));
+ EXPECT_FALSE(URL::hostIsIPAddress("127.0.0"));
+ EXPECT_FALSE(URL::hostIsIPAddress("127.0 .0.1"));
+ EXPECT_FALSE(URL::hostIsIPAddress(" 127.0.0.1"));
+ EXPECT_FALSE(URL::hostIsIPAddress("127..0.0.1"));
+ EXPECT_FALSE(URL::hostIsIPAddress("127.0.0."));
+ EXPECT_FALSE(URL::hostIsIPAddress("0123:4567:89AB:cdef:3210:7654:ba98"));
+ EXPECT_FALSE(URL::hostIsIPAddress("012x:4567:89AB:cdef:3210:7654:ba98:FeDc"));
+ EXPECT_FALSE(URL::hostIsIPAddress("00123:4567:89AB:cdef:3210:7654:ba98:FeDc"));
+ EXPECT_FALSE(URL::hostIsIPAddress("0123:4567:89AB:cdef:3210:123.45.67.89"));
+ EXPECT_FALSE(URL::hostIsIPAddress(":::"));
+
+ EXPECT_TRUE(URL::hostIsIPAddress("127.0.0.1"));
+ EXPECT_TRUE(URL::hostIsIPAddress("123.45.67.89"));
+ EXPECT_TRUE(URL::hostIsIPAddress("0.0.0.0"));
+ EXPECT_TRUE(URL::hostIsIPAddress("::1"));
+ EXPECT_TRUE(URL::hostIsIPAddress("::"));
+ EXPECT_TRUE(URL::hostIsIPAddress("0123:4567:89AB:cdef:3210:7654:ba98:FeDc"));
+ EXPECT_TRUE(URL::hostIsIPAddress("0123:4567:89AB:cdef:3210:7654:ba98::"));
+ EXPECT_TRUE(URL::hostIsIPAddress("::4567:89AB:cdef:3210:7654:ba98:FeDc"));
+ EXPECT_TRUE(URL::hostIsIPAddress("0123:4567:89AB:cdef:3210:7654:123.45.67.89"));
+ EXPECT_TRUE(URL::hostIsIPAddress("::123.45.67.89"));
+}
+
} // namespace TestWebKitAPI