OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/common/extensions/manifest_handlers/externally_connectable.h" | 5 #include "chrome/common/extensions/manifest_handlers/externally_connectable.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/common/extensions/api/manifest_types.h" | 8 #include "chrome/common/extensions/api/manifest_types.h" |
9 #include "chrome/common/extensions/extension_manifest_constants.h" | 9 #include "chrome/common/extensions/extension_manifest_constants.h" |
10 #include "extensions/common/error_utils.h" | 10 #include "extensions/common/error_utils.h" |
11 #include "extensions/common/url_pattern.h" | 11 #include "extensions/common/url_pattern.h" |
12 #include "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
| 13 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 14 |
| 15 namespace rcd = net::registry_controlled_domains; |
13 | 16 |
14 namespace extensions { | 17 namespace extensions { |
15 | 18 |
16 namespace externally_connectable_errors { | 19 namespace externally_connectable_errors { |
17 const char kErrorInvalid[] = "Invalid value for 'externally_connectable'"; | 20 const char kErrorInvalid[] = "Invalid value for 'externally_connectable'"; |
18 const char kErrorInvalidMatchPattern[] = "Invalid match pattern '*'"; | 21 const char kErrorInvalidMatchPattern[] = "Invalid match pattern '*'"; |
19 const char kErrorInvalidId[] = "Invalid ID '*'"; | 22 const char kErrorInvalidId[] = "Invalid ID '*'"; |
| 23 const char kErrorTopLevelDomainsNotAllowed[] = |
| 24 "\"*\" is an effective top level domain for which wildcard subdomains such " |
| 25 "as \"*\" are not allowed"; |
| 26 const char kErrorWildcardHostsNotAllowed[] = |
| 27 "Wildcard domain patterns such as \"*\" are not allowed"; |
20 } | 28 } |
21 | 29 |
22 namespace keys = extension_manifest_keys; | 30 namespace keys = extension_manifest_keys; |
23 namespace errors = externally_connectable_errors; | 31 namespace errors = externally_connectable_errors; |
24 using api::manifest_types::ExternallyConnectable; | 32 using api::manifest_types::ExternallyConnectable; |
25 | 33 |
26 namespace { | 34 namespace { |
27 const char kAllIds[] = "*"; | 35 const char kAllIds[] = "*"; |
28 } | 36 } |
29 | 37 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 externally_connectable->matches->begin(); | 81 externally_connectable->matches->begin(); |
74 it != externally_connectable->matches->end(); ++it) { | 82 it != externally_connectable->matches->end(); ++it) { |
75 // Safe to use SCHEME_ALL here; externally_connectable gives a page -> | 83 // Safe to use SCHEME_ALL here; externally_connectable gives a page -> |
76 // extension communication path, not the other way. | 84 // extension communication path, not the other way. |
77 URLPattern pattern(URLPattern::SCHEME_ALL); | 85 URLPattern pattern(URLPattern::SCHEME_ALL); |
78 if (pattern.Parse(*it) != URLPattern::PARSE_SUCCESS) { | 86 if (pattern.Parse(*it) != URLPattern::PARSE_SUCCESS) { |
79 *error = ErrorUtils::FormatErrorMessageUTF16( | 87 *error = ErrorUtils::FormatErrorMessageUTF16( |
80 errors::kErrorInvalidMatchPattern, *it); | 88 errors::kErrorInvalidMatchPattern, *it); |
81 return scoped_ptr<ExternallyConnectableInfo>(); | 89 return scoped_ptr<ExternallyConnectableInfo>(); |
82 } | 90 } |
| 91 |
| 92 // Wildcard hosts are not allowed. |
| 93 if (pattern.host().empty()) { |
| 94 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 95 errors::kErrorWildcardHostsNotAllowed, *it); |
| 96 return scoped_ptr<ExternallyConnectableInfo>(); |
| 97 } |
| 98 |
| 99 // Wildcards on subdomains of a TLD are not allowed. |
| 100 size_t registry_length = rcd::GetRegistryLength( |
| 101 pattern.host(), |
| 102 // This means that things that look like TLDs - the foobar in |
| 103 // http://google.foobar - count as TLDs. |
| 104 rcd::INCLUDE_UNKNOWN_REGISTRIES, |
| 105 // This means that effective TLDs like appspot.com count as TLDs; |
| 106 // codereview.appspot.com and evil.appspot.com are different. |
| 107 rcd::INCLUDE_PRIVATE_REGISTRIES); |
| 108 |
| 109 if (registry_length == std::string::npos) { |
| 110 // The URL parsing combined with host().empty() should have caught this. |
| 111 NOTREACHED() << *it; |
| 112 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 113 errors::kErrorInvalidMatchPattern, *it); |
| 114 return scoped_ptr<ExternallyConnectableInfo>(); |
| 115 } |
| 116 |
| 117 // Broad match patterns like "*.com", "*.co.uk", and even "*.appspot.com" |
| 118 // are not allowed. However just "appspot.com" is ok. |
| 119 if (registry_length == 0 && pattern.match_subdomains()) { |
| 120 *error = ErrorUtils::FormatErrorMessageUTF16( |
| 121 errors::kErrorTopLevelDomainsNotAllowed, |
| 122 pattern.host().c_str(), |
| 123 *it); |
| 124 return scoped_ptr<ExternallyConnectableInfo>(); |
| 125 } |
| 126 |
83 matches.AddPattern(pattern); | 127 matches.AddPattern(pattern); |
84 } | 128 } |
85 } | 129 } |
86 | 130 |
87 std::vector<std::string> ids; | 131 std::vector<std::string> ids; |
88 bool matches_all_ids = false; | 132 bool matches_all_ids = false; |
89 | 133 |
90 if (externally_connectable->ids) { | 134 if (externally_connectable->ids) { |
91 for (std::vector<std::string>::iterator it = | 135 for (std::vector<std::string>::iterator it = |
92 externally_connectable->ids->begin(); | 136 externally_connectable->ids->begin(); |
(...skipping 16 matching lines...) Expand all Loading... |
109 | 153 |
110 ExternallyConnectableInfo::~ExternallyConnectableInfo() {} | 154 ExternallyConnectableInfo::~ExternallyConnectableInfo() {} |
111 | 155 |
112 ExternallyConnectableInfo::ExternallyConnectableInfo( | 156 ExternallyConnectableInfo::ExternallyConnectableInfo( |
113 const URLPatternSet& matches, | 157 const URLPatternSet& matches, |
114 const std::vector<std::string>& ids, | 158 const std::vector<std::string>& ids, |
115 bool matches_all_ids) | 159 bool matches_all_ids) |
116 : matches(matches), ids(ids), matches_all_ids(matches_all_ids) {} | 160 : matches(matches), ids(ids), matches_all_ids(matches_all_ids) {} |
117 | 161 |
118 } // namespace extensions | 162 } // namespace extensions |
OLD | NEW |