OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007 Apple 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 | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 #include "wtf/StdLibExtras.h" | 42 #include "wtf/StdLibExtras.h" |
43 #include "wtf/text/StringBuilder.h" | 43 #include "wtf/text/StringBuilder.h" |
44 | 44 |
45 namespace blink { | 45 namespace blink { |
46 | 46 |
47 const int InvalidPort = 0; | 47 const int InvalidPort = 0; |
48 const int MaxAllowedPort = 65535; | 48 const int MaxAllowedPort = 65535; |
49 | 49 |
50 static SecurityOriginCache* s_originCache = 0; | 50 static SecurityOriginCache* s_originCache = 0; |
51 | 51 |
52 static bool schemeRequiresAuthority(const KURL& url) | |
53 { | |
54 // We expect URLs with these schemes to have authority components. If the | |
55 // URL lacks an authority component, we get concerned and mark the origin | |
56 // as unique. | |
57 return url.protocolIsInHTTPFamily() || url.protocolIs("ftp"); | |
58 } | |
59 | |
60 static SecurityOrigin* cachedOrigin(const KURL& url) | 52 static SecurityOrigin* cachedOrigin(const KURL& url) |
61 { | 53 { |
62 if (s_originCache) | 54 if (s_originCache) |
63 return s_originCache->cachedOrigin(url); | 55 return s_originCache->cachedOrigin(url); |
64 return 0; | 56 return 0; |
65 } | 57 } |
66 | 58 |
67 bool SecurityOrigin::shouldUseInnerURL(const KURL& url) | 59 bool SecurityOrigin::shouldUseInnerURL(const KURL& url) |
68 { | 60 { |
69 // FIXME: Blob URLs don't have inner URLs. Their form is "blob:<inner-origin >/<UUID>", so treating the part after "blob:" as a URL is incorrect. | 61 // FIXME: Blob URLs don't have inner URLs. Their form is "blob:<inner-origin >/<UUID>", so treating the part after "blob:" as a URL is incorrect. |
(...skipping 16 matching lines...) Expand all Loading... | |
86 return KURL(ParsedURLString, decodeURLEscapeSequences(url.path())); | 78 return KURL(ParsedURLString, decodeURLEscapeSequences(url.path())); |
87 } | 79 } |
88 | 80 |
89 void SecurityOrigin::setCache(SecurityOriginCache* originCache) | 81 void SecurityOrigin::setCache(SecurityOriginCache* originCache) |
90 { | 82 { |
91 s_originCache = originCache; | 83 s_originCache = originCache; |
92 } | 84 } |
93 | 85 |
94 static bool shouldTreatAsUniqueOrigin(const KURL& url) | 86 static bool shouldTreatAsUniqueOrigin(const KURL& url) |
95 { | 87 { |
96 if (!url.isValid()) | 88 if (!url.isValid()) |
palmer
2015/08/27 22:59:03
Add a comment here saying that URLs with schemes t
michaeln
2015/08/28 23:15:51
Done, also said it in an ASSERT
| |
97 return true; | 89 return true; |
98 | 90 |
99 // FIXME: Do we need to unwrap the URL further? | 91 // FIXME: Do we need to unwrap the URL further? |
100 KURL relevantURL; | 92 KURL relevantURL; |
101 if (SecurityOrigin::shouldUseInnerURL(url)) { | 93 if (SecurityOrigin::shouldUseInnerURL(url)) { |
102 relevantURL = SecurityOrigin::extractInnerURL(url); | 94 relevantURL = SecurityOrigin::extractInnerURL(url); |
103 if (!relevantURL.isValid()) | 95 if (!relevantURL.isValid()) |
104 return true; | 96 return true; |
105 } else { | 97 } else { |
106 relevantURL = url; | 98 relevantURL = url; |
107 } | 99 } |
108 | 100 |
109 // For edge case URLs that were probably misparsed, make sure that the origi n is unique. | |
110 // FIXME: Do we really need to do this? This looks to be a hack around a | |
111 // security bug in CFNetwork that might have been fixed. | |
112 if (schemeRequiresAuthority(relevantURL) && relevantURL.host().isEmpty()) | |
113 return true; | |
114 | |
115 // SchemeRegistry needs a lower case protocol because it uses HashMaps | 101 // SchemeRegistry needs a lower case protocol because it uses HashMaps |
116 // that assume the scheme has already been canonicalized. | 102 // that assume the scheme has already been canonicalized. |
117 String protocol = relevantURL.protocol().lower(); | 103 String protocol = relevantURL.protocol().lower(); |
118 | 104 |
119 if (SchemeRegistry::shouldTreatURLSchemeAsNoAccess(protocol)) | 105 if (SchemeRegistry::shouldTreatURLSchemeAsNoAccess(protocol)) |
120 return true; | 106 return true; |
121 | 107 |
122 // This is the common case. | 108 // This is the common case. |
123 return false; | 109 return false; |
124 } | 110 } |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
549 } | 535 } |
550 | 536 |
551 void SecurityOrigin::transferPrivilegesFrom(const SecurityOrigin& origin) | 537 void SecurityOrigin::transferPrivilegesFrom(const SecurityOrigin& origin) |
552 { | 538 { |
553 m_universalAccess = origin.m_universalAccess; | 539 m_universalAccess = origin.m_universalAccess; |
554 m_canLoadLocalResources = origin.m_canLoadLocalResources; | 540 m_canLoadLocalResources = origin.m_canLoadLocalResources; |
555 m_blockLocalAccessFromLocalOrigin = origin.m_blockLocalAccessFromLocalOrigin ; | 541 m_blockLocalAccessFromLocalOrigin = origin.m_blockLocalAccessFromLocalOrigin ; |
556 } | 542 } |
557 | 543 |
558 } // namespace blink | 544 } // namespace blink |
OLD | NEW |