OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Portions of this code based on Mozilla: | 5 // Portions of this code based on Mozilla: |
6 // (netwerk/cookie/src/nsCookieService.cpp) | 6 // (netwerk/cookie/src/nsCookieService.cpp) |
7 /* ***** BEGIN LICENSE BLOCK ***** | 7 /* ***** BEGIN LICENSE BLOCK ***** |
8 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 | 8 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
9 * | 9 * |
10 * The contents of this file are subject to the Mozilla Public License Version | 10 * The contents of this file are subject to the Mozilla Public License Version |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 std::string cookie_domain; | 188 std::string cookie_domain; |
189 if (!GetCookieDomain(url, parsed_cookie, &cookie_domain)) { | 189 if (!GetCookieDomain(url, parsed_cookie, &cookie_domain)) { |
190 VLOG(kVlogSetCookies) << "Create() failed to get a cookie domain"; | 190 VLOG(kVlogSetCookies) << "Create() failed to get a cookie domain"; |
191 return nullptr; | 191 return nullptr; |
192 } | 192 } |
193 | 193 |
194 // Per 3.2.1 of "Deprecate modification of 'secure' cookies from non-secure | 194 // Per 3.2.1 of "Deprecate modification of 'secure' cookies from non-secure |
195 // origins", if the cookie's "secure-only-flag" is "true" and the requesting | 195 // origins", if the cookie's "secure-only-flag" is "true" and the requesting |
196 // URL does not have a secure scheme, the cookie should be thrown away. | 196 // URL does not have a secure scheme, the cookie should be thrown away. |
197 // https://tools.ietf.org/html/draft-ietf-httpbis-cookie-alone | 197 // https://tools.ietf.org/html/draft-ietf-httpbis-cookie-alone |
198 if (options.enforce_strict_secure() && parsed_cookie.IsSecure() && | 198 if (parsed_cookie.IsSecure() && !url.SchemeIsCryptographic()) { |
199 !url.SchemeIsCryptographic()) { | |
200 VLOG(kVlogSetCookies) | 199 VLOG(kVlogSetCookies) |
201 << "Create() is trying to create a secure cookie from an insecure URL"; | 200 << "Create() is trying to create a secure cookie from an insecure URL"; |
202 return nullptr; | 201 return nullptr; |
203 } | 202 } |
204 | 203 |
205 std::string cookie_path = CanonicalCookie::CanonPath(url, parsed_cookie); | 204 std::string cookie_path = CanonicalCookie::CanonPath(url, parsed_cookie); |
206 Time server_time(creation_time); | 205 Time server_time(creation_time); |
207 if (options.has_server_time()) | 206 if (options.has_server_time()) |
208 server_time = options.server_time(); | 207 server_time = options.server_time(); |
209 | 208 |
(...skipping 23 matching lines...) Expand all Loading... |
233 const GURL& url, | 232 const GURL& url, |
234 const std::string& name, | 233 const std::string& name, |
235 const std::string& value, | 234 const std::string& value, |
236 const std::string& domain, | 235 const std::string& domain, |
237 const std::string& path, | 236 const std::string& path, |
238 const base::Time& creation, | 237 const base::Time& creation, |
239 const base::Time& expiration, | 238 const base::Time& expiration, |
240 bool secure, | 239 bool secure, |
241 bool http_only, | 240 bool http_only, |
242 CookieSameSite same_site, | 241 CookieSameSite same_site, |
243 bool enforce_strict_secure, | |
244 CookiePriority priority) { | 242 CookiePriority priority) { |
245 // Expect valid attribute tokens and values, as defined by the ParsedCookie | 243 // Expect valid attribute tokens and values, as defined by the ParsedCookie |
246 // logic, otherwise don't create the cookie. | 244 // logic, otherwise don't create the cookie. |
247 std::string parsed_name = ParsedCookie::ParseTokenString(name); | 245 std::string parsed_name = ParsedCookie::ParseTokenString(name); |
248 if (parsed_name != name) | 246 if (parsed_name != name) |
249 return nullptr; | 247 return nullptr; |
250 std::string parsed_value = ParsedCookie::ParseValueString(value); | 248 std::string parsed_value = ParsedCookie::ParseValueString(value); |
251 if (parsed_value != value) | 249 if (parsed_value != value) |
252 return nullptr; | 250 return nullptr; |
253 | 251 |
254 std::string parsed_domain = ParsedCookie::ParseValueString(domain); | 252 std::string parsed_domain = ParsedCookie::ParseValueString(domain); |
255 if (parsed_domain != domain) | 253 if (parsed_domain != domain) |
256 return nullptr; | 254 return nullptr; |
257 std::string cookie_domain; | 255 std::string cookie_domain; |
258 if (!cookie_util::GetCookieDomainWithString(url, parsed_domain, | 256 if (!cookie_util::GetCookieDomainWithString(url, parsed_domain, |
259 &cookie_domain)) { | 257 &cookie_domain)) { |
260 return nullptr; | 258 return nullptr; |
261 } | 259 } |
262 | 260 |
263 if (enforce_strict_secure && secure && !url.SchemeIsCryptographic()) | 261 if (secure && !url.SchemeIsCryptographic()) |
264 return nullptr; | 262 return nullptr; |
265 | 263 |
266 std::string parsed_path = ParsedCookie::ParseValueString(path); | 264 std::string parsed_path = ParsedCookie::ParseValueString(path); |
267 if (parsed_path != path) | 265 if (parsed_path != path) |
268 return nullptr; | 266 return nullptr; |
269 | 267 |
270 std::string cookie_path = CanonPathWithString(url, parsed_path); | 268 std::string cookie_path = CanonPathWithString(url, parsed_path); |
271 // Expect that the path was either not specified (empty), or is valid. | 269 // Expect that the path was either not specified (empty), or is valid. |
272 if (!parsed_path.empty() && cookie_path != parsed_path) | 270 if (!parsed_path.empty() && cookie_path != parsed_path) |
273 return nullptr; | 271 return nullptr; |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 return true; | 521 return true; |
524 } | 522 } |
525 | 523 |
526 std::string CanonicalCookie::DomainWithoutDot() const { | 524 std::string CanonicalCookie::DomainWithoutDot() const { |
527 if (domain_.empty() || domain_[0] != '.') | 525 if (domain_.empty() || domain_[0] != '.') |
528 return domain_; | 526 return domain_; |
529 return domain_.substr(1); | 527 return domain_.substr(1); |
530 } | 528 } |
531 | 529 |
532 } // namespace net | 530 } // namespace net |
OLD | NEW |