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

Side by Side Diff: Source/core/loader/MixedContentChecker.cpp

Issue 537983002: Mixed Content: introduce WebURLRequest::RequestContext checks. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase. Created 6 years, 3 months 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/core/loader/MixedContentChecker.h ('k') | no next file » | 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) 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 26 matching lines...) Expand all
37 #include "core/loader/FrameLoader.h" 37 #include "core/loader/FrameLoader.h"
38 #include "core/loader/FrameLoaderClient.h" 38 #include "core/loader/FrameLoaderClient.h"
39 #include "platform/RuntimeEnabledFeatures.h" 39 #include "platform/RuntimeEnabledFeatures.h"
40 #include "platform/weborigin/SchemeRegistry.h" 40 #include "platform/weborigin/SchemeRegistry.h"
41 #include "platform/weborigin/SecurityOrigin.h" 41 #include "platform/weborigin/SecurityOrigin.h"
42 #include "public/platform/Platform.h" 42 #include "public/platform/Platform.h"
43 #include "wtf/text/StringBuilder.h" 43 #include "wtf/text/StringBuilder.h"
44 44
45 namespace blink { 45 namespace blink {
46 46
47 namespace {
48 } // namespace
49
47 MixedContentChecker::MixedContentChecker(LocalFrame* frame) 50 MixedContentChecker::MixedContentChecker(LocalFrame* frame)
48 : m_frame(frame) 51 : m_frame(frame)
49 { 52 {
50 } 53 }
51 54
52 FrameLoaderClient* MixedContentChecker::client() const 55 FrameLoaderClient* MixedContentChecker::client() const
53 { 56 {
54 return m_frame->loader().client(); 57 return m_frame->loader().client();
55 } 58 }
56 59
57 // static 60 // static
58 bool MixedContentChecker::isMixedContent(SecurityOrigin* securityOrigin, const K URL& url) 61 bool MixedContentChecker::isMixedContent(SecurityOrigin* securityOrigin, const K URL& url)
59 { 62 {
60 if (securityOrigin->protocol() != "https") 63 if (securityOrigin->protocol() != "https")
61 return false; // We only care about HTTPS security origins. 64 return false; // We only care about HTTPS security origins.
62 65
63 // We're in a secure context, so |url| is mixed content if it's insecure. 66 // We're in a secure context, so |url| is mixed content if it's insecure.
64 return !SecurityOrigin::isSecure(url); 67 return !SecurityOrigin::isSecure(url);
65 } 68 }
66 69
70 // static
71 MixedContentChecker::ContextType MixedContentChecker::contextTypeFromContext(Web URLRequest::RequestContext context)
72 {
73 switch (context) {
74 // "Optionally-blockable" mixed content
75 case WebURLRequest::RequestContextAudio:
76 case WebURLRequest::RequestContextFavicon:
77 case WebURLRequest::RequestContextImage:
78 case WebURLRequest::RequestContextVideo:
79 return ContextTypeOptionallyBlockable;
80
81 // "Blockable" mixed content
82 case WebURLRequest::RequestContextBeacon:
83 case WebURLRequest::RequestContextCSPReport:
84 case WebURLRequest::RequestContextEmbed:
85 case WebURLRequest::RequestContextFetch:
86 case WebURLRequest::RequestContextFont:
87 case WebURLRequest::RequestContextForm:
88 case WebURLRequest::RequestContextFrame:
89 case WebURLRequest::RequestContextHyperlink:
90 case WebURLRequest::RequestContextIframe:
91 case WebURLRequest::RequestContextImageSet:
92 case WebURLRequest::RequestContextImport:
93 case WebURLRequest::RequestContextLocation:
94 case WebURLRequest::RequestContextManifest:
95 case WebURLRequest::RequestContextObject:
96 case WebURLRequest::RequestContextPing:
97 case WebURLRequest::RequestContextScript:
98 case WebURLRequest::RequestContextServiceWorker:
99 case WebURLRequest::RequestContextSharedWorker:
100 case WebURLRequest::RequestContextStyle:
101 case WebURLRequest::RequestContextSubresource:
102 case WebURLRequest::RequestContextTrack:
103 case WebURLRequest::RequestContextWorker:
104 case WebURLRequest::RequestContextXSLT:
105 return ContextTypeBlockable;
106
107 // "Blockable" mixed content whose behavior changed recently, and which is t hus guarded behind the "lax" flag
108 case WebURLRequest::RequestContextEventSource:
109 case WebURLRequest::RequestContextXMLHttpRequest:
110 return ContextTypeBlockableUnlessLax;
111
112 // Contexts that we should block, but don't currently.
113 case WebURLRequest::RequestContextDownload:
114 case WebURLRequest::RequestContextInternal:
115 case WebURLRequest::RequestContextPlugin:
116 case WebURLRequest::RequestContextPrefetch:
117 return ContextTypeShouldBeBlockable;
118
119 case WebURLRequest::RequestContextUnspecified:
120 ASSERT_NOT_REACHED();
121 }
122 ASSERT_NOT_REACHED();
123 return ContextTypeBlockable;
124 }
125
126 // static
127 bool MixedContentChecker::shouldBlockFetch(LocalFrame* frame, const ResourceRequ est& resourceRequest, const KURL& url)
128 {
129 // No frame, no mixed content:
130 if (!frame)
131 return false;
132
133 // Check the top frame first.
134 if (Frame* top = frame->tree().top()) {
135 // FIXME: We need a way to access the top-level frame's SecurityOrigin w hen that frame
136 // is in a different process from the current frame. Until that is done, we bail out
137 // early and allow the load.
138 if (!top->isLocalFrame())
139 return false;
140
141 LocalFrame* localTop = toLocalFrame(top);
142 if (frame != localTop && shouldBlockFetch(localTop, resourceRequest, url ))
143 return true;
144 }
145
146 // We only care about subresource loads; top-level navigations cannot be mix ed content.
147 if (resourceRequest.frameType() == WebURLRequest::FrameTypeTopLevel)
148 return false;
149
150 // No mixed content, no problem.
151 if (!isMixedContent(frame->document()->securityOrigin(), url))
152 return false;
153
154 Settings* settings = frame->settings();
155 FrameLoaderClient* client = frame->loader().client();
156 SecurityOrigin* securityOrigin = frame->document()->securityOrigin();
157 bool allowed = false;
158
159 switch (contextTypeFromContext(resourceRequest.requestContext())) {
160 case ContextTypeOptionallyBlockable:
161 allowed = client->allowDisplayingInsecureContent(settings && settings->a llowDisplayOfInsecureContent(), securityOrigin, url);
162 if (allowed)
163 client->didDisplayInsecureContent();
164 return !allowed;
165
166 case ContextTypeBlockable:
167 allowed = client->allowRunningInsecureContent(settings && settings->allo wRunningOfInsecureContent(), securityOrigin, url);
168 if (allowed)
169 client->didRunInsecureContent(securityOrigin, url);
170 return !allowed;
171
172 case ContextTypeBlockableUnlessLax:
173 if (RuntimeEnabledFeatures::laxMixedContentCheckingEnabled()) {
174 allowed = client->allowDisplayingInsecureContent(settings && setting s->allowDisplayOfInsecureContent(), securityOrigin, url);
175 if (allowed)
176 client->didDisplayInsecureContent();
177 } else {
178 allowed = client->allowRunningInsecureContent(settings && settings-> allowRunningOfInsecureContent(), securityOrigin, url);
179 if (allowed)
180 client->didRunInsecureContent(securityOrigin, url);
181 }
182 return !allowed;
183
184 case ContextTypeShouldBeBlockable:
185 return false;
186 };
187 ASSERT_NOT_REACHED();
188 return true;
189 }
190
67 bool MixedContentChecker::canDisplayInsecureContentInternal(SecurityOrigin* secu rityOrigin, const KURL& url, const MixedContentType type) const 191 bool MixedContentChecker::canDisplayInsecureContentInternal(SecurityOrigin* secu rityOrigin, const KURL& url, const MixedContentType type) const
68 { 192 {
69 // Check the top frame if it differs from MixedContentChecker's m_frame. 193 // Check the top frame if it differs from MixedContentChecker's m_frame.
70 if (!m_frame->tree().top()->isLocalFrame()) { 194 if (!m_frame->tree().top()->isLocalFrame()) {
71 // FIXME: We need a way to access the top-level frame's MixedContentChec ker when that frame 195 // FIXME: We need a way to access the top-level frame's MixedContentChec ker when that frame
72 // is in a different process from the current frame. Until that is done, we always allow 196 // is in a different process from the current frame. Until that is done, we always allow
73 // loads in remote frames. 197 // loads in remote frames.
74 return false; 198 return false;
75 } 199 }
76 Frame* top = m_frame->tree().top(); 200 Frame* top = m_frame->tree().top();
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 break; 299 break;
176 case Submission: 300 case Submission:
177 message.append("is submitting data to an insecure location at '" + targe t.elidedString() + "': this content should also be submitted over HTTPS.\n"); 301 message.append("is submitting data to an insecure location at '" + targe t.elidedString() + "': this content should also be submitted over HTTPS.\n");
178 break; 302 break;
179 } 303 }
180 MessageLevel messageLevel = allowed ? WarningMessageLevel : ErrorMessageLeve l; 304 MessageLevel messageLevel = allowed ? WarningMessageLevel : ErrorMessageLeve l;
181 m_frame->document()->addConsoleMessage(ConsoleMessage::create(SecurityMessag eSource, messageLevel, message.toString())); 305 m_frame->document()->addConsoleMessage(ConsoleMessage::create(SecurityMessag eSource, messageLevel, message.toString()));
182 } 306 }
183 307
184 } // namespace blink 308 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/loader/MixedContentChecker.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698