Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 if (!url.isValid()) | 55 if (!url.isValid()) |
| 56 return false; | 56 return false; |
| 57 | 57 |
| 58 url::RawCanonOutputT<char, 128> ignoredOutput; | 58 url::RawCanonOutputT<char, 128> ignoredOutput; |
| 59 url::CanonHostInfo hostInfo; | 59 url::CanonHostInfo hostInfo; |
| 60 url::Component hostComponent(0, static_cast<int>(url.host().utf8().length()) ); | 60 url::Component hostComponent(0, static_cast<int>(url.host().utf8().length()) ); |
| 61 url::CanonicalizeIPAddress(url.host().utf8().data(), hostComponent, &ignored Output, &hostInfo); | 61 url::CanonicalizeIPAddress(url.host().utf8().data(), hostComponent, &ignored Output, &hostInfo); |
| 62 return hostInfo.IsIPAddress(); | 62 return hostInfo.IsIPAddress(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 bool IsSubdomainOfHost(const String& subdomain, const String& host) | |
| 66 { | |
| 67 if (subdomain.length() <= host.length()) | |
| 68 return false; | |
| 69 | |
| 70 if (subdomain[subdomain.length() - host.length() - 1] != '.') | |
| 71 return false; | |
| 72 | |
| 73 if (!subdomain.endsWith(host)) | |
| 74 return false; | |
| 75 | |
| 76 return true; | |
| 77 } | |
| 65 } | 78 } |
| 66 | 79 |
| 67 OriginAccessEntry::OriginAccessEntry(const String& protocol, const String& host, SubdomainSetting subdomainSetting) | 80 OriginAccessEntry::OriginAccessEntry(const String& protocol, const String& host, SubdomainSetting subdomainSetting) |
| 68 : m_protocol(protocol.lower()) | 81 : m_protocol(protocol.lower()) |
| 69 , m_host(host.lower()) | 82 , m_host(host.lower()) |
| 70 , m_subdomainSettings(subdomainSetting) | 83 , m_subdomainSettings(subdomainSetting) |
| 71 , m_hostIsPublicSuffix(false) | 84 , m_hostIsPublicSuffix(false) |
| 72 { | 85 { |
| 73 ASSERT(subdomainSetting == AllowSubdomains || subdomainSetting == DisallowSu bdomains); | 86 ASSERT(subdomainSetting >= AllowSubdomains || subdomainSetting <= DisallowSu bdomains); |
| 74 | 87 |
| 75 m_hostIsIPAddress = HostIsIPAddress(host); | 88 m_hostIsIPAddress = HostIsIPAddress(host); |
| 76 | 89 |
| 77 // Look for top-level domains, either with or without an additional dot. | 90 // Look for top-level domains, either with or without an additional dot. |
| 78 if (!m_hostIsIPAddress) { | 91 if (!m_hostIsIPAddress) { |
| 79 WebPublicSuffixList* suffixList = Platform::current()->publicSuffixList( ); | 92 WebPublicSuffixList* suffixList = Platform::current()->publicSuffixList( ); |
| 80 if (suffixList && m_host.length() <= suffixList->getPublicSuffixLength(m _host) + 1) | 93 if (!suffixList) |
| 94 return; | |
| 95 | |
| 96 size_t publicSuffixLength = suffixList->getPublicSuffixLength(m_host); | |
| 97 if (m_host.length() <= publicSuffixLength + 1) { | |
| 81 m_hostIsPublicSuffix = true; | 98 m_hostIsPublicSuffix = true; |
| 99 } else if (subdomainSetting == AllowRegisterableDomains && publicSuffixL ength) { | |
| 100 // The "2" in the next line is 1 for the '.', plus a 1-char minimum label length. | |
| 101 const size_t dot = m_host.reverseFind('.', m_host.length() - publicS uffixLength - 2); | |
| 102 if (dot == kNotFound) | |
| 103 m_registerableDomain = host; | |
| 104 else | |
| 105 m_registerableDomain = host.substring(dot + 1); | |
|
jochen (gone - plz use gerrit)
2015/05/29 11:36:43
shouldn't this take this short list into account:
Mike West
2015/05/29 12:06:42
It does, insofar as the start position of the `rev
| |
| 106 } | |
| 82 } | 107 } |
| 83 } | 108 } |
| 84 | 109 |
| 85 OriginAccessEntry::MatchResult OriginAccessEntry::matchesOrigin(const SecurityOr igin& origin) const | 110 OriginAccessEntry::MatchResult OriginAccessEntry::matchesOrigin(const SecurityOr igin& origin) const |
| 86 { | 111 { |
| 87 ASSERT(origin.host() == origin.host().lower()); | 112 ASSERT(origin.host() == origin.host().lower()); |
| 88 ASSERT(origin.protocol() == origin.protocol().lower()); | 113 ASSERT(origin.protocol() == origin.protocol().lower()); |
| 89 | 114 |
| 90 if (m_protocol != origin.protocol()) | 115 if (m_protocol != origin.protocol()) |
| 91 return DoesNotMatchOrigin; | 116 return DoesNotMatchOrigin; |
| 92 | 117 |
| 93 // Special case: Include subdomains and empty host means "all hosts, includi ng ip addresses". | 118 // Special case: Include subdomains and empty host means "all hosts, includi ng ip addresses". |
| 94 if (m_subdomainSettings == AllowSubdomains && m_host.isEmpty()) | 119 if (m_subdomainSettings != DisallowSubdomains && m_host.isEmpty()) |
| 95 return MatchesOrigin; | 120 return MatchesOrigin; |
| 96 | 121 |
| 97 // Exact match. | 122 // Exact match. |
| 98 if (m_host == origin.host()) | 123 if (m_host == origin.host()) |
| 99 return MatchesOrigin; | 124 return MatchesOrigin; |
| 100 | 125 |
| 101 // Otherwise we can only match if we're matching subdomains. | |
| 102 if (m_subdomainSettings == DisallowSubdomains) | |
| 103 return DoesNotMatchOrigin; | |
| 104 | |
| 105 // Don't try to do subdomain matching on IP addresses. | 126 // Don't try to do subdomain matching on IP addresses. |
| 106 if (m_hostIsIPAddress) | 127 if (m_hostIsIPAddress) |
| 107 return DoesNotMatchOrigin; | 128 return DoesNotMatchOrigin; |
| 108 | 129 |
| 109 // Match subdomains. | 130 // Match subdomains. |
| 110 if (origin.host().length() <= m_host.length() || origin.host()[origin.host() .length() - m_host.length() - 1] != '.' || !origin.host().endsWith(m_host)) | 131 switch (m_subdomainSettings) { |
| 132 case DisallowSubdomains: | |
| 111 return DoesNotMatchOrigin; | 133 return DoesNotMatchOrigin; |
| 112 | 134 |
| 135 case AllowSubdomains: | |
| 136 if (!IsSubdomainOfHost(origin.host(), m_host)) | |
| 137 return DoesNotMatchOrigin; | |
| 138 break; | |
| 139 | |
| 140 case AllowRegisterableDomains: | |
| 141 // Fall back to a simple subdomain check if no registerable domain could be found: | |
| 142 if (m_registerableDomain.isEmpty()) { | |
| 143 if (!IsSubdomainOfHost(origin.host(), m_host)) | |
| 144 return DoesNotMatchOrigin; | |
| 145 } else if (m_registerableDomain != origin.host() && !IsSubdomainOfHost(o rigin.host(), m_registerableDomain)) { | |
| 146 return DoesNotMatchOrigin; | |
| 147 } | |
| 148 break; | |
| 149 }; | |
| 150 | |
| 113 if (m_hostIsPublicSuffix) | 151 if (m_hostIsPublicSuffix) |
| 114 return MatchesOriginButIsPublicSuffix; | 152 return MatchesOriginButIsPublicSuffix; |
| 115 | 153 |
| 116 return MatchesOrigin; | 154 return MatchesOrigin; |
| 117 } | 155 } |
| 118 | 156 |
| 119 } // namespace blink | 157 } // namespace blink |
| OLD | NEW |