Chromium Code Reviews| Index: extensions/common/manifest_handlers/externally_connectable.cc |
| diff --git a/extensions/common/manifest_handlers/externally_connectable.cc b/extensions/common/manifest_handlers/externally_connectable.cc |
| index 7dcdaffcb546269e0230463cbde36ba8b0b18f70..fc9b6a7e3e1508f5373336db94c0d2456b9e08e8 100644 |
| --- a/extensions/common/manifest_handlers/externally_connectable.cc |
| +++ b/extensions/common/manifest_handlers/externally_connectable.cc |
| @@ -20,6 +20,7 @@ |
| #include "extensions/common/permissions/api_permission_set.h" |
| #include "extensions/common/url_pattern.h" |
| #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| +#include "net/base/url_util.h" |
| #include "url/gurl.h" |
| namespace rcd = net::registry_controlled_domains; |
| @@ -139,9 +140,21 @@ std::unique_ptr<ExternallyConnectableInfo> ExternallyConnectableInfo::FromValue( |
| continue; |
| } |
| + url::CanonHostInfo host_info; |
| + std::string canonical_host = |
| + net::CanonicalizeHost(pattern.host(), &host_info); |
| + if (canonical_host.empty()) { |
| + // CanonicalizeHost returns empty string on error. The URL parsing |
| + // combined with host().empty() should have caught this above. |
| + NOTREACHED() << *it; |
|
Peter Kasting
2016/10/22 05:04:18
This violates the style guide by handling NOTREACH
brettw
2016/10/24 21:45:23
I was also unhappy with this function when I was w
Peter Kasting
2016/10/24 23:04:32
Pretty sure we need to handle malicious input here
asargent_no_longer_on_chrome
2016/10/25 18:20:49
For context, this check is less about security and
Peter Kasting
2016/10/25 20:28:17
Will it? If so, then handling this makes sense, b
asargent_no_longer_on_chrome
2016/10/25 20:57:13
Taking a quick look at the code for URLPattern::Pa
Peter Kasting
2016/10/25 21:05:19
OK. I'm fine with that outcome, as long as we hav
asargent_no_longer_on_chrome
2016/10/25 23:37:55
Hmm, the tricky part about doing that in general i
|
| + *error = ErrorUtils::FormatErrorMessageUTF16( |
| + errors::kErrorInvalidMatchPattern, *it); |
| + return std::unique_ptr<ExternallyConnectableInfo>(); |
| + } |
| + |
| // Wildcards on subdomains of a TLD are not allowed. |
| - size_t registry_length = rcd::GetRegistryLength( |
| - pattern.host(), |
| + bool has_registry = rcd::HostHasRegistryControlledDomain( |
| + canonical_host, |
|
Peter Kasting
2016/10/22 05:04:18
Nit: Seems like using pattern.host() here is fine
brettw
2016/10/24 21:45:23
If we're keeping the code above (which I think we
Peter Kasting
2016/10/24 23:04:32
Seems fair, I mostly said this because I'm convinc
|
| // This means that things that look like TLDs - the foobar in |
| // http://google.foobar - count as TLDs. |
| rcd::INCLUDE_UNKNOWN_REGISTRIES, |
| @@ -149,17 +162,9 @@ std::unique_ptr<ExternallyConnectableInfo> ExternallyConnectableInfo::FromValue( |
| // codereview.appspot.com and evil.appspot.com are different. |
| rcd::INCLUDE_PRIVATE_REGISTRIES); |
| - if (registry_length == std::string::npos) { |
| - // The URL parsing combined with host().empty() should have caught this. |
| - NOTREACHED() << *it; |
| - *error = ErrorUtils::FormatErrorMessageUTF16( |
| - errors::kErrorInvalidMatchPattern, *it); |
| - return std::unique_ptr<ExternallyConnectableInfo>(); |
| - } |
| - |
| // Broad match patterns like "*.com", "*.co.uk", and even "*.appspot.com" |
| // are not allowed. However just "appspot.com" is ok. |
| - if (registry_length == 0 && pattern.match_subdomains()) { |
| + if (!has_registry && pattern.match_subdomains()) { |
| // Warning not error for forwards compatibility. |
| install_warnings->push_back( |
| InstallWarning(ErrorUtils::FormatErrorMessage( |