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

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

Issue 623683002: Mixed Content: Extract frame processing from ::shouldBlockFetch. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixing preloader. Created 6 years, 2 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
« 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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 void MixedContentChecker::logToConsole(LocalFrame* frame, const KURL& url, WebUR LRequest::RequestContext requestContext, bool allowed) 205 void MixedContentChecker::logToConsole(LocalFrame* frame, const KURL& url, WebUR LRequest::RequestContext requestContext, bool allowed)
206 { 206 {
207 String message = String::format( 207 String message = String::format(
208 "Mixed Content: The page at '%s' was loaded over HTTPS, but requested an insecure %s '%s'. %s", 208 "Mixed Content: The page at '%s' was loaded over HTTPS, but requested an insecure %s '%s'. %s",
209 frame->document()->url().elidedString().utf8().data(), typeNameFromConte xt(requestContext), url.elidedString().utf8().data(), 209 frame->document()->url().elidedString().utf8().data(), typeNameFromConte xt(requestContext), url.elidedString().utf8().data(),
210 allowed ? "This content should also be served over HTTPS." : "This reque st has been blocked; the content must be served over HTTPS."); 210 allowed ? "This content should also be served over HTTPS." : "This reque st has been blocked; the content must be served over HTTPS.");
211 MessageLevel messageLevel = allowed ? WarningMessageLevel : ErrorMessageLeve l; 211 MessageLevel messageLevel = allowed ? WarningMessageLevel : ErrorMessageLeve l;
212 frame->document()->addConsoleMessage(ConsoleMessage::create(SecurityMessageS ource, messageLevel, message)); 212 frame->document()->addConsoleMessage(ConsoleMessage::create(SecurityMessageS ource, messageLevel, message));
213 } 213 }
214 214
215 // static 215 LocalFrame* MixedContentChecker::inWhichFrameIsThisContentMixed(LocalFrame* fram e, WebURLRequest::RequestContext requestContext, WebURLRequest::FrameType frameT ype, const KURL& url)
216 bool MixedContentChecker::shouldBlockFetch(LocalFrame* frame, const ResourceRequ est& resourceRequest, const KURL& url)
217 { 216 {
218 // No frame, no mixed content: 217 // No frame, no mixed content:
219 if (!frame) 218 if (!frame)
220 return false; 219 return nullptr;
220
221 // We only care about subresource loads; top-level navigations cannot be mix ed content.
222 if (frameType == WebURLRequest::FrameTypeTopLevel)
223 return nullptr;
221 224
222 // Check the top frame first. 225 // Check the top frame first.
223 if (Frame* top = frame->tree().top()) { 226 if (Frame* top = frame->tree().top()) {
224 // FIXME: We need a way to access the top-level frame's SecurityOrigin w hen that frame 227 // FIXME: We need a way to access the top-level frame's SecurityOrigin w hen that frame
225 // is in a different process from the current frame. Until that is done, we bail out 228 // is in a different process from the current frame. Until that is done, we bail out
226 // early and allow the load. 229 // early and allow the load.
227 if (!top->isLocalFrame()) 230 if (!top->isLocalFrame())
228 return false; 231 return nullptr;
229 232
230 LocalFrame* localTop = toLocalFrame(top); 233 LocalFrame* localTop = toLocalFrame(top);
231 if (frame != localTop && shouldBlockFetch(localTop, resourceRequest, url )) 234 if (frame != localTop && inWhichFrameIsThisContentMixed(localTop, reques tContext, frameType, url))
232 return true; 235 return localTop;
233 } 236 }
234 237
235 // We only care about subresource loads; top-level navigations cannot be mix ed content. 238 // Just count these for the moment, don't block them.
236 if (resourceRequest.frameType() == WebURLRequest::FrameTypeTopLevel) 239 if (Platform::current()->isReservedIPAddress(url) && !Platform::current()->i sReservedIPAddress(KURL(ParsedURLString, frame->document()->securityOrigin()->to String())))
237 return false; 240 UseCounter::count(frame->document(), contextTypeFromContext(requestConte xt) == ContextTypeBlockable ? UseCounter::MixedContentPrivateIPInPublicWebsiteAc tive : UseCounter::MixedContentPrivateIPInPublicWebsitePassive);
238 241
239 // No mixed content, no problem. 242 // No mixed content, no problem.
240 if (!isMixedContent(frame->document()->securityOrigin(), url)) 243 if (!isMixedContent(frame->document()->securityOrigin(), url))
244 return nullptr;
245
246 return frame;
247 }
248
249 // static
250 bool MixedContentChecker::shouldBlockFetch(LocalFrame* frame, WebURLRequest::Req uestContext requestContext, WebURLRequest::FrameType frameType, const KURL& url)
251 {
252 LocalFrame* effectiveFrame = inWhichFrameIsThisContentMixed(frame, requestCo ntext, frameType, url);
253 if (!effectiveFrame)
241 return false; 254 return false;
242 255
243 Settings* settings = frame->settings(); 256 // We grab the settings and client from the frame in which the content was m ixed, as it might be
244 FrameLoaderClient* client = frame->loader().client(); 257 // configured to allow mixed content in a different way than the frame in wh ich the content
245 SecurityOrigin* securityOrigin = frame->document()->securityOrigin(); 258 // loads (e.g. if Frame A is allowed to frame an insecure Frame B, we defer to Frame A's settings
259 // when evaluating Frame B's subresource loads). Yes, this is confusing.
260 Settings* settings = effectiveFrame->settings();
261 FrameLoaderClient* client = effectiveFrame->loader().client();
262 SecurityOrigin* securityOrigin = effectiveFrame->document()->securityOrigin( );
246 bool allowed = false; 263 bool allowed = false;
247 264
248 ContextType contextType = contextTypeFromContext(resourceRequest.requestCont ext()); 265 ContextType contextType = contextTypeFromContext(requestContext);
249 if (contextType == ContextTypeBlockableUnlessLax) 266 if (contextType == ContextTypeBlockableUnlessLax)
250 contextType = RuntimeEnabledFeatures::laxMixedContentCheckingEnabled() ? ContextTypeOptionallyBlockable : ContextTypeBlockable; 267 contextType = RuntimeEnabledFeatures::laxMixedContentCheckingEnabled() ? ContextTypeOptionallyBlockable : ContextTypeBlockable;
251 268
252 switch (contextType) { 269 switch (contextType) {
253 case ContextTypeOptionallyBlockable: 270 case ContextTypeOptionallyBlockable:
254 allowed = client->allowDisplayingInsecureContent(settings && settings->a llowDisplayOfInsecureContent(), securityOrigin, url); 271 allowed = client->allowDisplayingInsecureContent(settings && settings->a llowDisplayOfInsecureContent(), securityOrigin, url);
255 if (allowed) 272 if (allowed)
256 client->didDisplayInsecureContent(); 273 client->didDisplayInsecureContent();
257 break; 274 break;
258 275
259 case ContextTypeBlockable: 276 case ContextTypeBlockable:
260 allowed = client->allowRunningInsecureContent(settings && settings->allo wRunningOfInsecureContent(), securityOrigin, url); 277 allowed = client->allowRunningInsecureContent(settings && settings->allo wRunningOfInsecureContent(), securityOrigin, url);
261 if (allowed) 278 if (allowed)
262 client->didRunInsecureContent(securityOrigin, url); 279 client->didRunInsecureContent(securityOrigin, url);
263 break; 280 break;
264 281
265 case ContextTypeShouldBeBlockable: 282 case ContextTypeShouldBeBlockable:
266 return false; 283 return false;
267 284
268 case ContextTypeBlockableUnlessLax: 285 case ContextTypeBlockableUnlessLax:
269 // We map this to either OptionallyBlockable or Blockable above. 286 // We map this to either OptionallyBlockable or Blockable above.
270 ASSERT_NOT_REACHED(); 287 ASSERT_NOT_REACHED();
271 return true; 288 return true;
272 }; 289 };
273 290
274 logToConsole(frame, url, resourceRequest.requestContext(), allowed); 291 // While we use the |effectiveFrame| to grab the settings object, we log the console error in
292 // |frame|, where the violation actually happened.
293 String message = String::format(
294 "Mixed Content: The page at '%s' was loaded over HTTPS, but requested an insecure %s '%s'. %s",
295 frame->document()->url().elidedString().utf8().data(), typeNameFromConte xt(requestContext), url.elidedString().utf8().data(),
296 allowed ? "This content should also be served over HTTPS." : "This reque st has been blocked; the content must be served over HTTPS.");
297 MessageLevel messageLevel = allowed ? WarningMessageLevel : ErrorMessageLeve l;
298 frame->document()->addConsoleMessage(ConsoleMessage::create(SecurityMessageS ource, messageLevel, message));
299
275 return !allowed; 300 return !allowed;
276 } 301 }
277 302
278 bool MixedContentChecker::canDisplayInsecureContentInternal(SecurityOrigin* secu rityOrigin, const KURL& url, const MixedContentType type) const 303 bool MixedContentChecker::canDisplayInsecureContentInternal(SecurityOrigin* secu rityOrigin, const KURL& url, const MixedContentType type) const
279 { 304 {
280 // Check the top frame if it differs from MixedContentChecker's m_frame. 305 // Check the top frame if it differs from MixedContentChecker's m_frame.
281 if (!m_frame->tree().top()->isLocalFrame()) { 306 if (!m_frame->tree().top()->isLocalFrame()) {
282 // FIXME: We need a way to access the top-level frame's MixedContentChec ker when that frame 307 // FIXME: We need a way to access the top-level frame's MixedContentChec ker when that frame
283 // is in a different process from the current frame. Until that is done, we always allow 308 // is in a different process from the current frame. Until that is done, we always allow
284 // loads in remote frames. 309 // loads in remote frames.
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 if (Platform::current()->isReservedIPAddress(resourceIP) && !Platform::curre nt()->isReservedIPAddress(documentIP)) 431 if (Platform::current()->isReservedIPAddress(resourceIP) && !Platform::curre nt()->isReservedIPAddress(documentIP))
407 UseCounter::count(frame->document(), UseCounter::MixedContentPrivateHost nameInPublicHostname); 432 UseCounter::count(frame->document(), UseCounter::MixedContentPrivateHost nameInPublicHostname);
408 } 433 }
409 434
410 void MixedContentChecker::trace(Visitor* visitor) 435 void MixedContentChecker::trace(Visitor* visitor)
411 { 436 {
412 visitor->trace(m_frame); 437 visitor->trace(m_frame);
413 } 438 }
414 439
415 } // namespace blink 440 } // 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