OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 * | 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 19 matching lines...) Expand all Loading... | |
30 #include "core/loader/MixedContentChecker.h" | 30 #include "core/loader/MixedContentChecker.h" |
31 | 31 |
32 #include "core/dom/Document.h" | 32 #include "core/dom/Document.h" |
33 #include "core/frame/LocalFrame.h" | 33 #include "core/frame/LocalFrame.h" |
34 #include "core/frame/Settings.h" | 34 #include "core/frame/Settings.h" |
35 #include "core/loader/FrameLoader.h" | 35 #include "core/loader/FrameLoader.h" |
36 #include "core/loader/FrameLoaderClient.h" | 36 #include "core/loader/FrameLoaderClient.h" |
37 #include "platform/RuntimeEnabledFeatures.h" | 37 #include "platform/RuntimeEnabledFeatures.h" |
38 #include "platform/weborigin/SchemeRegistry.h" | 38 #include "platform/weborigin/SchemeRegistry.h" |
39 #include "platform/weborigin/SecurityOrigin.h" | 39 #include "platform/weborigin/SecurityOrigin.h" |
40 #include "public/platform/Platform.h" | |
41 #include "public/platform/WebURL.h" | |
40 #include "wtf/text/StringBuilder.h" | 42 #include "wtf/text/StringBuilder.h" |
41 | 43 |
42 namespace blink { | 44 namespace blink { |
43 | 45 |
44 MixedContentChecker::MixedContentChecker(LocalFrame* frame) | 46 MixedContentChecker::MixedContentChecker(LocalFrame* frame) |
45 : m_frame(frame) | 47 : m_frame(frame) |
46 { | 48 { |
47 } | 49 } |
48 | 50 |
49 FrameLoaderClient* MixedContentChecker::client() const | 51 FrameLoaderClient* MixedContentChecker::client() const |
50 { | 52 { |
51 return m_frame->loader().client(); | 53 return m_frame->loader().client(); |
52 } | 54 } |
53 | 55 |
54 // static | 56 // static |
57 bool MixedContentChecker::isMixedRealm(SecurityOrigin* securityOrigin, const KUR L& url) | |
58 { | |
59 if (RuntimeEnabledFeatures::laxMixedContentCheckingEnabled()) | |
60 return false; | |
61 | |
62 // We only care about public origins: private origins can load public resour ces without issue. | |
63 KURL originURL; | |
64 originURL.setProtocol(securityOrigin->protocol()); | |
65 originURL.setHost(securityOrigin->host()); | |
66 if (!Platform::current()->isReservedIPAddress(originURL)) | |
Mike West
2014/08/06 09:08:14
I would like to pass the SecurityOrigin to the pla
| |
67 return false; | |
68 | |
69 return Platform::current()->isReservedIPAddress(url); | |
70 } | |
71 | |
72 // static | |
55 bool MixedContentChecker::isMixedContent(SecurityOrigin* securityOrigin, const K URL& url) | 73 bool MixedContentChecker::isMixedContent(SecurityOrigin* securityOrigin, const K URL& url) |
56 { | 74 { |
57 if (securityOrigin->protocol() != "https") | 75 if (securityOrigin->protocol() != "https") |
58 return false; // We only care about HTTPS security origins. | 76 return false; // We only care about HTTPS security origins. |
59 | 77 |
60 // We're in a secure context, so |url| is mixed content if it's insecure. | 78 // We're in a secure context, so |url| is mixed content if it's insecure. |
61 return !SecurityOrigin::isSecure(url); | 79 return !SecurityOrigin::isSecure(url); |
62 } | 80 } |
63 | 81 |
64 bool MixedContentChecker::canDisplayInsecureContentInternal(SecurityOrigin* secu rityOrigin, const KURL& url, const MixedContentType type) const | 82 bool MixedContentChecker::canDisplayInsecureContentInternal(SecurityOrigin* secu rityOrigin, const KURL& url, const MixedContentType type) const |
65 { | 83 { |
66 // Check the top frame if it differs from MixedContentChecker's m_frame. | 84 // Check the top frame if it differs from MixedContentChecker's m_frame. |
67 if (!m_frame->tree().top()->isLocalFrame()) { | 85 if (!m_frame->tree().top()->isLocalFrame()) { |
68 // FIXME: We need a way to access the top-level frame's MixedContentChec ker when that frame | 86 // FIXME: We need a way to access the top-level frame's MixedContentChec ker when that frame |
69 // is in a different process from the current frame. Until that is done, we always allow | 87 // is in a different process from the current frame. Until that is done, we always allow |
70 // loads in remote frames. | 88 // loads in remote frames. |
71 return false; | 89 return false; |
72 } | 90 } |
73 Frame* top = m_frame->tree().top(); | 91 Frame* top = m_frame->tree().top(); |
74 if (top != m_frame && !toLocalFrame(top)->loader().mixedContentChecker()->ca nDisplayInsecureContent(toLocalFrame(top)->document()->securityOrigin(), url)) | 92 if (top != m_frame && !toLocalFrame(top)->loader().mixedContentChecker()->ca nDisplayInsecureContent(toLocalFrame(top)->document()->securityOrigin(), url)) |
75 return false; | 93 return false; |
76 | 94 |
77 // Then check the current frame: | 95 // Then check the current frame: |
78 if (!isMixedContent(securityOrigin, url)) | 96 if (!isMixedContent(securityOrigin, url) && !isMixedRealm(securityOrigin, ur l)) |
79 return true; | 97 return true; |
80 | 98 |
81 Settings* settings = m_frame->settings(); | 99 Settings* settings = m_frame->settings(); |
82 bool allowed = client()->allowDisplayingInsecureContent(settings && settings ->allowDisplayOfInsecureContent(), securityOrigin, url); | 100 bool allowed = client()->allowDisplayingInsecureContent(settings && settings ->allowDisplayOfInsecureContent(), securityOrigin, url); |
83 logWarning(allowed, url, type); | 101 logWarning(allowed, url, type); |
84 | 102 |
85 if (allowed) | 103 if (allowed) |
86 client()->didDisplayInsecureContent(); | 104 client()->didDisplayInsecureContent(); |
87 | 105 |
88 return allowed; | 106 return allowed; |
89 } | 107 } |
90 | 108 |
91 bool MixedContentChecker::canRunInsecureContentInternal(SecurityOrigin* security Origin, const KURL& url, const MixedContentType type) const | 109 bool MixedContentChecker::canRunInsecureContentInternal(SecurityOrigin* security Origin, const KURL& url, const MixedContentType type) const |
92 { | 110 { |
93 // Check the top frame if it differs from MixedContentChecker's m_frame. | 111 // Check the top frame if it differs from MixedContentChecker's m_frame. |
94 if (!m_frame->tree().top()->isLocalFrame()) { | 112 if (!m_frame->tree().top()->isLocalFrame()) { |
95 // FIXME: We need a way to access the top-level frame's MixedContentChec ker when that frame | 113 // FIXME: We need a way to access the top-level frame's MixedContentChec ker when that frame |
96 // is in a different process from the current frame. Until that is done, we always allow | 114 // is in a different process from the current frame. Until that is done, we always allow |
97 // loads in remote frames. | 115 // loads in remote frames. |
98 return false; | 116 return false; |
99 } | 117 } |
100 Frame* top = m_frame->tree().top(); | 118 Frame* top = m_frame->tree().top(); |
101 if (top != m_frame && !toLocalFrame(top)->loader().mixedContentChecker()->ca nRunInsecureContent(toLocalFrame(top)->document()->securityOrigin(), url)) | 119 if (top != m_frame && !toLocalFrame(top)->loader().mixedContentChecker()->ca nRunInsecureContent(toLocalFrame(top)->document()->securityOrigin(), url)) |
102 return false; | 120 return false; |
103 | 121 |
104 // Then check the current frame: | 122 // Then check the current frame: |
105 if (!isMixedContent(securityOrigin, url)) | 123 if (!isMixedContent(securityOrigin, url) && !isMixedRealm(securityOrigin, ur l)) |
106 return true; | 124 return true; |
107 | 125 |
108 Settings* settings = m_frame->settings(); | 126 Settings* settings = m_frame->settings(); |
109 bool allowedPerSettings = settings && (settings->allowRunningOfInsecureConte nt() || ((type == WebSocket) && settings->allowConnectingInsecureWebSocket())); | 127 bool allowedPerSettings = settings && (settings->allowRunningOfInsecureConte nt() || ((type == WebSocket) && settings->allowConnectingInsecureWebSocket())); |
110 bool allowed = client()->allowRunningInsecureContent(allowedPerSettings, sec urityOrigin, url); | 128 bool allowed = client()->allowRunningInsecureContent(allowedPerSettings, sec urityOrigin, url); |
111 logWarning(allowed, url, type); | 129 logWarning(allowed, url, type); |
112 | 130 |
113 if (allowed) | 131 if (allowed) |
114 client()->didRunInsecureContent(securityOrigin, url); | 132 client()->didRunInsecureContent(securityOrigin, url); |
115 | 133 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 break; | 182 break; |
165 case Submission: | 183 case Submission: |
166 message.append("is submitting data to an insecure location at '" + targe t.elidedString() + "': this content should also be submitted over HTTPS.\n"); | 184 message.append("is submitting data to an insecure location at '" + targe t.elidedString() + "': this content should also be submitted over HTTPS.\n"); |
167 break; | 185 break; |
168 } | 186 } |
169 MessageLevel messageLevel = allowed ? WarningMessageLevel : ErrorMessageLeve l; | 187 MessageLevel messageLevel = allowed ? WarningMessageLevel : ErrorMessageLeve l; |
170 m_frame->document()->addConsoleMessage(SecurityMessageSource, messageLevel, message.toString()); | 188 m_frame->document()->addConsoleMessage(SecurityMessageSource, messageLevel, message.toString()); |
171 } | 189 } |
172 | 190 |
173 } // namespace blink | 191 } // namespace blink |
OLD | NEW |