OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All Rights Reserved. | 2 * Copyright (C) 2011 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 | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 10 matching lines...) Expand all Loading... | |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 * | 24 * |
25 */ | 25 */ |
26 | 26 |
27 #ifndef SecurityContext_h | 27 #ifndef SecurityContext_h |
28 #define SecurityContext_h | 28 #define SecurityContext_h |
29 | 29 |
30 #include "core/dom/SandboxFlags.h" | 30 #include "core/dom/SandboxFlags.h" |
31 #include "wtf/HashSet.h" | |
32 #include "wtf/PassRefPtr.h" | 31 #include "wtf/PassRefPtr.h" |
33 #include "wtf/RefPtr.h" | 32 #include "wtf/RefPtr.h" |
34 #include "wtf/text/StringHash.h" | |
35 #include "wtf/text/WTFString.h" | 33 #include "wtf/text/WTFString.h" |
36 | 34 |
37 namespace blink { | 35 namespace blink { |
38 | 36 |
39 class SecurityOrigin; | 37 class SecurityOrigin; |
40 class ContentSecurityPolicy; | 38 class ContentSecurityPolicy; |
41 class KURL; | 39 class KURL; |
42 | 40 |
43 class SecurityContext { | 41 class SecurityContext { |
44 public: | 42 public: |
45 using InsecureNavigationsSet = HashSet<unsigned, WTF::AlreadyHashed>; | |
46 | |
47 // The ordering here is important: 'Upgrade' overrides 'DoNotUpgrade'. | 43 // The ordering here is important: 'Upgrade' overrides 'DoNotUpgrade'. |
48 enum InsecureRequestsPolicy { | 44 enum InsecureRequestsPolicy { |
49 InsecureRequestsDoNotUpgrade = 0, | 45 InsecureRequestsDoNotUpgrade = 0, |
50 InsecureRequestsUpgrade | 46 InsecureRequestsUpgrade |
51 }; | 47 }; |
52 | 48 |
53 SecurityOrigin* securityOrigin() const { return m_securityOrigin.get(); } | 49 SecurityOrigin* securityOrigin() const { return m_securityOrigin.get(); } |
54 ContentSecurityPolicy* contentSecurityPolicy() const { return m_contentSecur ityPolicy.get(); } | 50 ContentSecurityPolicy* contentSecurityPolicy() const { return m_contentSecur ityPolicy.get(); } |
55 | 51 |
56 bool isSecureTransitionTo(const KURL&) const; | 52 bool isSecureTransitionTo(const KURL&) const; |
57 | 53 |
58 // Explicitly override the security origin for this security context. | 54 // Explicitly override the security origin for this security context. |
59 // Note: It is dangerous to change the security origin of a script context | 55 // Note: It is dangerous to change the security origin of a script context |
60 // that already contains content. | 56 // that already contains content. |
61 void setSecurityOrigin(PassRefPtr<SecurityOrigin>); | 57 void setSecurityOrigin(PassRefPtr<SecurityOrigin>); |
62 virtual void didUpdateSecurityOrigin() = 0; | 58 virtual void didUpdateSecurityOrigin() = 0; |
63 | 59 |
64 SandboxFlags sandboxFlags() const { return m_sandboxFlags; } | 60 SandboxFlags sandboxFlags() const { return m_sandboxFlags; } |
65 bool isSandboxed(SandboxFlags mask) const { return m_sandboxFlags & mask; } | 61 bool isSandboxed(SandboxFlags mask) const { return m_sandboxFlags & mask; } |
66 void enforceSandboxFlags(SandboxFlags mask); | 62 void enforceSandboxFlags(SandboxFlags mask); |
67 | 63 |
68 void setHostedInReservedIPRange() { m_hostedInReservedIPRange = true; } | 64 void setHostedInReservedIPRange() { m_hostedInReservedIPRange = true; } |
69 bool isHostedInReservedIPRange() const { return m_hostedInReservedIPRange; } | 65 bool isHostedInReservedIPRange() const { return m_hostedInReservedIPRange; } |
70 | 66 |
71 void setInsecureRequestsPolicy(InsecureRequestsPolicy policy) { m_insecureRe questsPolicy = policy; } | 67 void setInsecureRequestsPolicy(InsecureRequestsPolicy policy) { m_insecureRe questsPolicy = policy; } |
72 InsecureRequestsPolicy insecureRequestsPolicy() const { return m_insecureReq uestsPolicy; } | 68 InsecureRequestsPolicy insecureRequestsPolicy() const { return m_insecureReq uestsPolicy; } |
73 | 69 |
74 void addInsecureNavigationUpgrade(const String& host) { m_insecureNavigation sToUpgrade.add(host.impl()->hash()); } | |
Yoav Weiss
2015/03/10 19:03:05
here we trusted host.impl() to be non-null. Are we
| |
75 void addInsecureNavigationUpgrade(unsigned hashedHost) { m_insecureNavigatio nsToUpgrade.add(hashedHost); } | |
76 InsecureNavigationsSet* insecureNavigationsToUpgrade() { return &m_insecureN avigationsToUpgrade; } | |
77 | |
78 protected: | 70 protected: |
79 SecurityContext(); | 71 SecurityContext(); |
80 virtual ~SecurityContext(); | 72 virtual ~SecurityContext(); |
81 | 73 |
82 void setContentSecurityPolicy(PassRefPtr<ContentSecurityPolicy>); | 74 void setContentSecurityPolicy(PassRefPtr<ContentSecurityPolicy>); |
83 | 75 |
84 void didFailToInitializeSecurityOrigin() { m_haveInitializedSecurityOrigin = false; } | 76 void didFailToInitializeSecurityOrigin() { m_haveInitializedSecurityOrigin = false; } |
85 bool haveInitializedSecurityOrigin() const { return m_haveInitializedSecurit yOrigin; } | 77 bool haveInitializedSecurityOrigin() const { return m_haveInitializedSecurit yOrigin; } |
86 | 78 |
87 private: | 79 private: |
88 bool m_haveInitializedSecurityOrigin; | 80 bool m_haveInitializedSecurityOrigin; |
89 RefPtr<SecurityOrigin> m_securityOrigin; | 81 RefPtr<SecurityOrigin> m_securityOrigin; |
90 RefPtr<ContentSecurityPolicy> m_contentSecurityPolicy; | 82 RefPtr<ContentSecurityPolicy> m_contentSecurityPolicy; |
91 | 83 |
92 SandboxFlags m_sandboxFlags; | 84 SandboxFlags m_sandboxFlags; |
93 | 85 |
94 bool m_hostedInReservedIPRange; | 86 bool m_hostedInReservedIPRange; |
95 InsecureRequestsPolicy m_insecureRequestsPolicy; | 87 InsecureRequestsPolicy m_insecureRequestsPolicy; |
96 InsecureNavigationsSet m_insecureNavigationsToUpgrade; | |
97 }; | 88 }; |
98 | 89 |
99 } // namespace blink | 90 } // namespace blink |
100 | 91 |
101 #endif // SecurityContext_h | 92 #endif // SecurityContext_h |
OLD | NEW |