Changeset 228261 in webkit
- Timestamp:
- Feb 7, 2018 10:37:10 PM (6 years ago)
- Location:
- trunk
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r228260 r228261 1 2018-02-05 Carlos Garcia Campos <cgarcia@igalia.com> 2 3 Add a way to check if a host is an IP address 4 https://bugs.webkit.org/show_bug.cgi?id=182427 5 6 Reviewed by Alex Christensen. 7 8 There are several places where this is needed. We currently just assume that any host ending in a digit is an IP 9 address, except in PublicSuffix where platform specific code is used. This patch adds URL::hostIsIPAddress() 10 platform specific implementations, falling back to current assumption if there isn't an implementation for the 11 platform. 12 13 * page/OriginAccessEntry.cpp: 14 (WebCore::OriginAccessEntry::OriginAccessEntry): Use URL::hostIsIPAddress(). 15 * platform/URL.cpp: 16 (WebCore::URL::hostIsIPAddress): Fallback implementation. 17 * platform/URL.h: 18 * platform/mac/PublicSuffixMac.mm: 19 (WebCore::topPrivatelyControlledDomain): Use URL::hostIsIPAddress(). 20 * platform/mac/URLMac.mm: 21 (WebCore::URL::hostIsIPAddress): Move implementation from PublicSuffixMac.mm. 22 * platform/network/curl/CookieUtil.cpp: 23 (WebCore::CookieUtil::isIPAddress): Use URL::hostIsIPAddress(). 24 * platform/soup/URLSoup.cpp: 25 (WebCore::URL::hostIsIPAddress): Use g_hostname_is_ip_address(). 26 1 27 2018-01-13 Darin Adler <darin@apple.com> 2 28 -
trunk/Source/WebCore/page/OriginAccessEntry.cpp
r228118 r228261 41 41 , m_subdomainSettings(subdomainSetting) 42 42 , m_ipAddressSettings(ipAddressSetting) 43 , m_hostIsIPAddress(URL::hostIsIPAddress(m_host)) 43 44 { 44 45 ASSERT(subdomainSetting == AllowSubdomains || subdomainSetting == DisallowSubdomains); 45 46 // Assume that any host that ends with a digit is trying to be an IP address.47 m_hostIsIPAddress = !m_host.isEmpty() && isASCIIDigit(m_host[m_host.length() - 1]);48 46 } 49 47 … … 70 68 // IP addresses are not domains: https://url.spec.whatwg.org/#concept-domain 71 69 // Don't try to do subdomain matching on IP addresses. 72 if (m_ hostIsIPAddress && m_ipAddressSettings == TreatIPAddressAsIPAddress)70 if (m_ipAddressSettings == TreatIPAddressAsIPAddress && (m_hostIsIPAddress || URL::hostIsIPAddress(origin.host()))) 73 71 return false; 74 72 -
trunk/Source/WebCore/platform/URL.cpp
r228118 r228261 1036 1036 } 1037 1037 1038 #if !PLATFORM(COCOA) && !USE(SOUP) 1039 bool URL::hostIsIPAddress(const String& host) 1040 { 1041 // Assume that any host that ends with a digit is trying to be an IP address. 1042 return !host.isEmpty() && isASCIIDigit(host[host.length() - 1]); 1043 } 1044 #endif 1045 1038 1046 } // namespace WebCore -
trunk/Source/WebCore/platform/URL.h
r228118 r228261 176 176 unsigned hostEnd() const; 177 177 178 WEBCORE_EXPORT static bool hostIsIPAddress(const String&); 179 178 180 unsigned pathStart() const; 179 181 unsigned pathEnd() const; -
trunk/Source/WebCore/platform/mac/PublicSuffixMac.mm
r228118 r228261 29 29 #if ENABLE(PUBLIC_SUFFIX_LIST) 30 30 31 #import " WebCoreNSURLExtras.h"31 #import "URL.h" 32 32 #import <pal/spi/cf/CFNetworkSPI.h> 33 34 @interface NSString (WebCoreNSURLExtras)35 - (BOOL)_web_looksLikeIPAddress;36 @end37 33 38 34 namespace WebCore { … … 46 42 String topPrivatelyControlledDomain(const String& domain) 47 43 { 48 if ( [domain _web_looksLikeIPAddress])44 if (URL::hostIsIPAddress(domain)) 49 45 return domain; 50 46 -
trunk/Source/WebCore/platform/mac/URLMac.mm
r228118 r228261 29 29 #import "CFURLExtras.h" 30 30 #import "URLParser.h" 31 #import "WebCoreNSURLExtras.h" 31 32 #import <wtf/ObjcRuntimeExtras.h> 32 33 #import <wtf/text/CString.h> 34 35 @interface NSString (WebCoreNSURLExtras) 36 - (BOOL)_web_looksLikeIPAddress; 37 @end 33 38 34 39 namespace WebCore { … … 75 80 } 76 81 82 bool URL::hostIsIPAddress(const String& host) 83 { 84 return [host _web_looksLikeIPAddress]; 77 85 } 86 87 } -
trunk/Source/WebCore/platform/network/curl/CookieUtil.cpp
r228118 r228261 54 54 bool isIPAddress(const String& hostname) 55 55 { 56 // Assuming that hosts ending in a digit are IP Addresses 57 return !hostname.isEmpty() && isASCIIDigit(hostname[hostname.length() - 1]); 56 return URL::hostIsIPAddress(hostname); 58 57 } 59 58 -
trunk/Source/WebCore/platform/soup/URLSoup.cpp
r228118 r228261 67 67 } 68 68 69 bool URL::hostIsIPAddress(const String& host) 70 { 71 return !host.isEmpty() && g_hostname_is_ip_address(host.utf8().data()); 72 } 73 69 74 } // namespace WebCore 70 75 -
trunk/Tools/ChangeLog
r228253 r228261 1 2018-02-05 Carlos Garcia Campos <cgarcia@igalia.com> 2 3 Add a way to check if a host is an IP address 4 https://bugs.webkit.org/show_bug.cgi?id=182427 5 6 Reviewed by Alex Christensen. 7 8 Add unit test for URL::hostIsIPAddress(). 9 10 * TestWebKitAPI/Tests/WebCore/URL.cpp: 11 (TestWebKitAPI::TEST_F): 12 1 13 2018-02-07 Tim Horton <timothy_horton@apple.com> 2 14 -
trunk/Tools/TestWebKitAPI/Tests/WebCore/URL.cpp
r228118 r228261 232 232 } 233 233 234 TEST_F(URLTest, HostIsIPAddress) 235 { 236 EXPECT_FALSE(URL::hostIsIPAddress({ })); 237 EXPECT_FALSE(URL::hostIsIPAddress("")); 238 EXPECT_FALSE(URL::hostIsIPAddress("localhost")); 239 EXPECT_FALSE(URL::hostIsIPAddress("127.localhost")); 240 EXPECT_FALSE(URL::hostIsIPAddress("localhost.127")); 241 EXPECT_FALSE(URL::hostIsIPAddress("127.0.0")); 242 EXPECT_FALSE(URL::hostIsIPAddress("127.0 .0.1")); 243 EXPECT_FALSE(URL::hostIsIPAddress(" 127.0.0.1")); 244 EXPECT_FALSE(URL::hostIsIPAddress("127..0.0.1")); 245 EXPECT_FALSE(URL::hostIsIPAddress("127.0.0.")); 246 EXPECT_FALSE(URL::hostIsIPAddress("0123:4567:89AB:cdef:3210:7654:ba98")); 247 EXPECT_FALSE(URL::hostIsIPAddress("012x:4567:89AB:cdef:3210:7654:ba98:FeDc")); 248 #if !PLATFORM(COCOA) 249 // FIXME: This fails in Mac. 250 EXPECT_FALSE(URL::hostIsIPAddress("00123:4567:89AB:cdef:3210:7654:ba98:FeDc")); 251 #endif 252 EXPECT_FALSE(URL::hostIsIPAddress("0123:4567:89AB:cdef:3210:123.45.67.89")); 253 EXPECT_FALSE(URL::hostIsIPAddress(":::")); 254 255 EXPECT_TRUE(URL::hostIsIPAddress("127.0.0.1")); 256 EXPECT_TRUE(URL::hostIsIPAddress("123.45.67.89")); 257 EXPECT_TRUE(URL::hostIsIPAddress("0.0.0.0")); 258 EXPECT_TRUE(URL::hostIsIPAddress("::1")); 259 EXPECT_TRUE(URL::hostIsIPAddress("::")); 260 EXPECT_TRUE(URL::hostIsIPAddress("0123:4567:89AB:cdef:3210:7654:ba98:FeDc")); 261 EXPECT_TRUE(URL::hostIsIPAddress("0123:4567:89AB:cdef:3210:7654:ba98::")); 262 EXPECT_TRUE(URL::hostIsIPAddress("::4567:89AB:cdef:3210:7654:ba98:FeDc")); 263 EXPECT_TRUE(URL::hostIsIPAddress("0123:4567:89AB:cdef:3210:7654:123.45.67.89")); 264 EXPECT_TRUE(URL::hostIsIPAddress("::123.45.67.89")); 265 } 266 234 267 } // namespace TestWebKitAPI
Note: See TracChangeset
for help on using the changeset viewer.