| 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 "extensions/common/csp_validator.h" | 5 #include "extensions/common/csp_validator.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
| 10 #include "base/strings/string_tokenizer.h" | 10 #include "base/strings/string_tokenizer.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 bool should_check_rcd) { | 47 bool should_check_rcd) { |
| 48 if (!StartsWithASCII(url, scheme_and_separator, true)) | 48 if (!StartsWithASCII(url, scheme_and_separator, true)) |
| 49 return false; | 49 return false; |
| 50 | 50 |
| 51 size_t start_of_host = scheme_and_separator.length(); | 51 size_t start_of_host = scheme_and_separator.length(); |
| 52 | 52 |
| 53 size_t end_of_host = url.find("/", start_of_host); | 53 size_t end_of_host = url.find("/", start_of_host); |
| 54 if (end_of_host == std::string::npos) | 54 if (end_of_host == std::string::npos) |
| 55 end_of_host = url.size(); | 55 end_of_host = url.size(); |
| 56 | 56 |
| 57 // A missing host such as "chrome-extension://" is invalid, but for backwards- |
| 58 // compatibility, accept such CSP parts. They will be ignored by Blink anyway. |
| 59 if (start_of_host == end_of_host) |
| 60 return true; |
| 61 |
| 57 // Note: It is sufficient to only compare the first character against '*' | 62 // Note: It is sufficient to only compare the first character against '*' |
| 58 // because the CSP only allows wildcards at the start of a directive, see | 63 // because the CSP only allows wildcards at the start of a directive, see |
| 59 // host-source and host-part at http://www.w3.org/TR/CSP2/#source-list-syntax | 64 // host-source and host-part at http://www.w3.org/TR/CSP2/#source-list-syntax |
| 60 bool is_wildcard_subdomain = end_of_host > start_of_host + 2 && | 65 bool is_wildcard_subdomain = end_of_host > start_of_host + 2 && |
| 61 url[start_of_host] == '*' && url[start_of_host + 1] == '.'; | 66 url[start_of_host] == '*' && url[start_of_host + 1] == '.'; |
| 62 if (is_wildcard_subdomain) | 67 if (is_wildcard_subdomain) |
| 63 start_of_host += 2; | 68 start_of_host += 2; |
| 64 | 69 |
| 65 size_t start_of_port = url.rfind(":", end_of_host); | 70 size_t start_of_port = url.rfind(":", end_of_host); |
| 66 // The ":" check at the end of the following condition is used to avoid | 71 // The ":" check at the end of the following condition is used to avoid |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 } | 247 } |
| 243 } | 248 } |
| 244 } | 249 } |
| 245 | 250 |
| 246 return seen_sandbox; | 251 return seen_sandbox; |
| 247 } | 252 } |
| 248 | 253 |
| 249 } // namespace csp_validator | 254 } // namespace csp_validator |
| 250 | 255 |
| 251 } // namespace extensions | 256 } // namespace extensions |
| OLD | NEW |