Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1663)

Side by Side Diff: Source/weborigin/OriginAccessEntry.cpp

Issue 50573004: Don't set document.domain to an IP address fragment. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: missing weboriginexport header Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/weborigin/OriginAccessEntry.h ('k') | Source/weborigin/SecurityPolicy.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 17 matching lines...) Expand all
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "weborigin/OriginAccessEntry.h" 32 #include "weborigin/OriginAccessEntry.h"
33 33
34 #include "weborigin/SecurityOrigin.h" 34 #include "weborigin/SecurityOrigin.h"
35 35
36 namespace WebCore { 36 namespace WebCore {
37 37
38 OriginAccessEntry::OriginAccessEntry(const String& protocol, const String& host, SubdomainSetting subdomainSetting) 38 OriginAccessEntry::OriginAccessEntry(const String& protocol, const String& host, SubdomainSetting subdomainSetting, IPAddressSetting ipAddressSetting)
39 : m_protocol(protocol.lower()) 39 : m_protocol(protocol.lower())
40 , m_host(host.lower()) 40 , m_host(host.lower())
41 , m_subdomainSettings(subdomainSetting) 41 , m_subdomainSettings(subdomainSetting)
42 , m_ipAddressSettings(ipAddressSetting)
42 { 43 {
43 ASSERT(subdomainSetting == AllowSubdomains || subdomainSetting == DisallowSu bdomains); 44 ASSERT(subdomainSetting == AllowSubdomains || subdomainSetting == DisallowSu bdomains);
44 45
45 // Assume that any host that ends with a digit is trying to be an IP address . 46 // Assume that any host that ends with a digit is trying to be an IP address .
46 m_hostIsIPAddress = !m_host.isEmpty() && isASCIIDigit(m_host[m_host.length() - 1]); 47 m_hostIsIPAddress = !m_host.isEmpty() && isASCIIDigit(m_host[m_host.length() - 1]);
47 } 48 }
48 49
49 bool OriginAccessEntry::matchesOrigin(const SecurityOrigin& origin) const 50 bool OriginAccessEntry::matchesOrigin(const SecurityOrigin& origin) const
50 { 51 {
51 ASSERT(origin.host() == origin.host().lower()); 52 ASSERT(origin.host() == origin.host().lower());
52 ASSERT(origin.protocol() == origin.protocol().lower()); 53 ASSERT(origin.protocol() == origin.protocol().lower());
53 54
54 if (m_protocol != origin.protocol()) 55 if (m_protocol != origin.protocol())
55 return false; 56 return false;
56 57
57 // Special case: Include subdomains and empty host means "all hosts, includi ng ip addresses". 58 // Special case: Include subdomains and empty host means "all hosts, includi ng ip addresses".
58 if (m_subdomainSettings == AllowSubdomains && m_host.isEmpty()) 59 if (m_subdomainSettings == AllowSubdomains && m_host.isEmpty())
59 return true; 60 return true;
60 61
61 // Exact match. 62 // Exact match.
62 if (m_host == origin.host()) 63 if (m_host == origin.host())
63 return true; 64 return true;
64 65
65 // Otherwise we can only match if we're matching subdomains. 66 // Otherwise we can only match if we're matching subdomains.
66 if (m_subdomainSettings == DisallowSubdomains) 67 if (m_subdomainSettings == DisallowSubdomains)
67 return false; 68 return false;
68 69
69 // Don't try to do subdomain matching on IP addresses. 70 // Don't try to do subdomain matching on IP addresses.
70 if (m_hostIsIPAddress) 71 if (m_hostIsIPAddress && m_ipAddressSettings == TreatIPAddressAsIPAddress)
71 return false; 72 return false;
72 73
73 // Match subdomains. 74 // Match subdomains.
74 if (origin.host().length() > m_host.length() && origin.host()[origin.host(). length() - m_host.length() - 1] == '.' && origin.host().endsWith(m_host)) 75 if (origin.host().length() > m_host.length() && origin.host()[origin.host(). length() - m_host.length() - 1] == '.' && origin.host().endsWith(m_host))
75 return true; 76 return true;
76 77
77 return false; 78 return false;
78 } 79 }
79 80
80 } // namespace WebCore 81 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/weborigin/OriginAccessEntry.h ('k') | Source/weborigin/SecurityPolicy.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698