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

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

Issue 2625633002: Supporting changes in preparation of browser side mixed content checking. (Closed)
Patch Set: Created 3 years, 11 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
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 25 matching lines...) Expand all
36 #include "core/inspector/ConsoleMessage.h" 36 #include "core/inspector/ConsoleMessage.h"
37 #include "core/loader/DocumentLoader.h" 37 #include "core/loader/DocumentLoader.h"
38 #include "core/loader/FrameLoader.h" 38 #include "core/loader/FrameLoader.h"
39 #include "core/loader/FrameLoaderClient.h" 39 #include "core/loader/FrameLoaderClient.h"
40 #include "platform/RuntimeEnabledFeatures.h" 40 #include "platform/RuntimeEnabledFeatures.h"
41 #include "platform/network/NetworkUtils.h" 41 #include "platform/network/NetworkUtils.h"
42 #include "platform/weborigin/SchemeRegistry.h" 42 #include "platform/weborigin/SchemeRegistry.h"
43 #include "platform/weborigin/SecurityOrigin.h" 43 #include "platform/weborigin/SecurityOrigin.h"
44 #include "public/platform/WebAddressSpace.h" 44 #include "public/platform/WebAddressSpace.h"
45 #include "public/platform/WebInsecureRequestPolicy.h" 45 #include "public/platform/WebInsecureRequestPolicy.h"
46 #include "public/platform/WebMixedContent.h"
47 #include "public/platform/WebMixedContentContextType.h"
46 #include "wtf/text/StringBuilder.h" 48 #include "wtf/text/StringBuilder.h"
47 49
48 namespace blink { 50 namespace blink {
49 51
50 namespace { 52 namespace {
51 53
52 // When a frame is local, use its full URL to represent the main resource. When 54 // When a frame is local, use its full URL to represent the main resource. When
53 // the frame is remote, the full URL isn't accessible, so use the origin. This 55 // the frame is remote, the full URL isn't accessible, so use the origin. This
54 // function is used, for example, to determine the URL to show in console 56 // function is used, for example, to determine the URL to show in console
55 // messages about mixed content. 57 // messages about mixed content.
56 KURL mainResourceUrlForFrame(Frame* frame) { 58 KURL mainResourceUrlForFrame(Frame* frame) {
57 if (frame->isRemoteFrame()) { 59 if (frame->isRemoteFrame()) {
58 return KURL(KURL(), 60 return KURL(KURL(),
59 frame->securityContext()->getSecurityOrigin()->toString()); 61 frame->securityContext()->getSecurityOrigin()->toString());
60 } 62 }
61 return toLocalFrame(frame)->document()->url(); 63 return toLocalFrame(frame)->document()->url();
62 } 64 }
63 65
66 const char* requestContextName(WebURLRequest::RequestContext context) {
67 switch (context) {
68 case WebURLRequest::RequestContextAudio:
69 return "audio file";
70 case WebURLRequest::RequestContextBeacon:
71 return "Beacon endpoint";
72 case WebURLRequest::RequestContextCSPReport:
73 return "Content Security Policy reporting endpoint";
74 case WebURLRequest::RequestContextDownload:
75 return "download";
76 case WebURLRequest::RequestContextEmbed:
77 return "plugin resource";
78 case WebURLRequest::RequestContextEventSource:
79 return "EventSource endpoint";
80 case WebURLRequest::RequestContextFavicon:
81 return "favicon";
82 case WebURLRequest::RequestContextFetch:
83 return "resource";
84 case WebURLRequest::RequestContextFont:
85 return "font";
86 case WebURLRequest::RequestContextForm:
87 return "form action";
88 case WebURLRequest::RequestContextFrame:
89 return "frame";
90 case WebURLRequest::RequestContextHyperlink:
91 return "resource";
92 case WebURLRequest::RequestContextIframe:
93 return "frame";
94 case WebURLRequest::RequestContextImage:
95 return "image";
96 case WebURLRequest::RequestContextImageSet:
97 return "image";
98 case WebURLRequest::RequestContextImport:
99 return "HTML Import";
100 case WebURLRequest::RequestContextInternal:
101 return "resource";
102 case WebURLRequest::RequestContextLocation:
103 return "resource";
104 case WebURLRequest::RequestContextManifest:
105 return "manifest";
106 case WebURLRequest::RequestContextObject:
107 return "plugin resource";
108 case WebURLRequest::RequestContextPing:
109 return "hyperlink auditing endpoint";
110 case WebURLRequest::RequestContextPlugin:
111 return "plugin data";
112 case WebURLRequest::RequestContextPrefetch:
113 return "prefetch resource";
114 case WebURLRequest::RequestContextScript:
115 return "script";
116 case WebURLRequest::RequestContextServiceWorker:
117 return "Service Worker script";
118 case WebURLRequest::RequestContextSharedWorker:
119 return "Shared Worker script";
120 case WebURLRequest::RequestContextStyle:
121 return "stylesheet";
122 case WebURLRequest::RequestContextSubresource:
123 return "resource";
124 case WebURLRequest::RequestContextTrack:
125 return "Text Track";
126 case WebURLRequest::RequestContextUnspecified:
127 return "resource";
128 case WebURLRequest::RequestContextVideo:
129 return "video";
130 case WebURLRequest::RequestContextWorker:
131 return "Worker script";
132 case WebURLRequest::RequestContextXMLHttpRequest:
133 return "XMLHttpRequest endpoint";
134 case WebURLRequest::RequestContextXSLT:
135 return "XSLT";
136 }
137 NOTREACHED();
138 return "resource";
139 }
140
64 } // namespace 141 } // namespace
65 142
66 static void measureStricterVersionOfIsMixedContent(Frame* frame, 143 static void measureStricterVersionOfIsMixedContent(Frame* frame,
67 const KURL& url) { 144 const KURL& url) {
68 // We're currently only checking for mixed content in `https://*` contexts. 145 // We're currently only checking for mixed content in `https://*` contexts.
69 // What about other "secure" contexts the SchemeRegistry knows about? We'll 146 // What about other "secure" contexts the SchemeRegistry knows about? We'll
70 // use this method to measure the occurance of non-webby mixed content to make 147 // use this method to measure the occurance of non-webby mixed content to make
71 // sure we're not breaking the world without realizing it. 148 // sure we're not breaking the world without realizing it.
72 SecurityOrigin* origin = frame->securityContext()->getSecurityOrigin(); 149 SecurityOrigin* origin = frame->securityContext()->getSecurityOrigin();
73 if (MixedContentChecker::isMixedContent(origin, url)) { 150 if (MixedContentChecker::isMixedContent(origin, url)) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 void MixedContentChecker::logToConsoleAboutFetch( 220 void MixedContentChecker::logToConsoleAboutFetch(
144 LocalFrame* frame, 221 LocalFrame* frame,
145 const KURL& mainResourceUrl, 222 const KURL& mainResourceUrl,
146 const KURL& url, 223 const KURL& url,
147 WebURLRequest::RequestContext requestContext, 224 WebURLRequest::RequestContext requestContext,
148 bool allowed) { 225 bool allowed) {
149 String message = String::format( 226 String message = String::format(
150 "Mixed Content: The page at '%s' was loaded over HTTPS, but requested an " 227 "Mixed Content: The page at '%s' was loaded over HTTPS, but requested an "
151 "insecure %s '%s'. %s", 228 "insecure %s '%s'. %s",
152 mainResourceUrl.elidedString().utf8().data(), 229 mainResourceUrl.elidedString().utf8().data(),
153 WebMixedContent::requestContextName(requestContext), 230 requestContextName(requestContext), url.elidedString().utf8().data(),
154 url.elidedString().utf8().data(),
155 allowed ? "This content should also be served over HTTPS." 231 allowed ? "This content should also be served over HTTPS."
156 : "This request has been blocked; the content must be served " 232 : "This request has been blocked; the content must be served "
157 "over HTTPS."); 233 "over HTTPS.");
158 MessageLevel messageLevel = allowed ? WarningMessageLevel : ErrorMessageLevel; 234 MessageLevel messageLevel = allowed ? WarningMessageLevel : ErrorMessageLevel;
159 frame->document()->addConsoleMessage( 235 frame->document()->addConsoleMessage(
160 ConsoleMessage::create(SecurityMessageSource, messageLevel, message)); 236 ConsoleMessage::create(SecurityMessageSource, messageLevel, message));
161 } 237 }
162 238
163 // static 239 // static
164 void MixedContentChecker::count(Frame* frame, 240 void MixedContentChecker::count(Frame* frame,
165 WebURLRequest::RequestContext requestContext) { 241 WebURLRequest::RequestContext requestContext) {
166 UseCounter::count(frame, UseCounter::MixedContentPresent); 242 UseCounter::count(frame, UseCounter::MixedContentPresent);
167 243
168 // Roll blockable content up into a single counter, count unblocked types 244 // Roll blockable content up into a single counter, count unblocked types
169 // individually so we can determine when they can be safely moved to the 245 // individually so we can determine when they can be safely moved to the
170 // blockable category: 246 // blockable category:
171 WebMixedContent::ContextType contextType = 247 WebMixedContentContextType contextType =
172 WebMixedContent::contextTypeFromRequestContext( 248 WebMixedContent::contextTypeFromRequestContext(
173 requestContext, 249 requestContext,
174 frame->settings()->getStrictMixedContentCheckingForPlugin()); 250 frame->settings()->getStrictMixedContentCheckingForPlugin());
175 if (contextType == WebMixedContent::ContextType::Blockable) { 251 if (contextType == WebMixedContentContextType::Blockable) {
176 UseCounter::count(frame, UseCounter::MixedContentBlockable); 252 UseCounter::count(frame, UseCounter::MixedContentBlockable);
177 return; 253 return;
178 } 254 }
179 255
180 UseCounter::Feature feature; 256 UseCounter::Feature feature;
181 switch (requestContext) { 257 switch (requestContext) {
182 case WebURLRequest::RequestContextAudio: 258 case WebURLRequest::RequestContextAudio:
183 feature = UseCounter::MixedContentAudio; 259 feature = UseCounter::MixedContentAudio;
184 break; 260 break;
185 case WebURLRequest::RequestContextDownload: 261 case WebURLRequest::RequestContextDownload:
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 mixedFrame->securityContext()->getSecurityOrigin(); 314 mixedFrame->securityContext()->getSecurityOrigin();
239 bool allowed = false; 315 bool allowed = false;
240 316
241 // If we're in strict mode, we'll automagically fail everything, and 317 // If we're in strict mode, we'll automagically fail everything, and
242 // intentionally skip the client checks in order to prevent degrading the 318 // intentionally skip the client checks in order to prevent degrading the
243 // site's security UI. 319 // site's security UI.
244 bool strictMode = mixedFrame->securityContext()->getInsecureRequestPolicy() & 320 bool strictMode = mixedFrame->securityContext()->getInsecureRequestPolicy() &
245 kBlockAllMixedContent || 321 kBlockAllMixedContent ||
246 settings->getStrictMixedContentChecking(); 322 settings->getStrictMixedContentChecking();
247 323
248 WebMixedContent::ContextType contextType = 324 WebMixedContentContextType contextType =
249 WebMixedContent::contextTypeFromRequestContext( 325 WebMixedContent::contextTypeFromRequestContext(
250 requestContext, settings->getStrictMixedContentCheckingForPlugin()); 326 requestContext, settings->getStrictMixedContentCheckingForPlugin());
251 327
252 // If we're loading the main resource of a subframe, we need to take a close 328 // If we're loading the main resource of a subframe, we need to take a close
253 // look at the loaded URL. If we're dealing with a CORS-enabled scheme, then 329 // look at the loaded URL. If we're dealing with a CORS-enabled scheme, then
254 // block mixed frames as active content. Otherwise, treat frames as passive 330 // block mixed frames as active content. Otherwise, treat frames as passive
255 // content. 331 // content.
256 // 332 //
257 // FIXME: Remove this temporary hack once we have a reasonable API for 333 // FIXME: Remove this temporary hack once we have a reasonable API for
258 // launching external applications via URLs. http://crbug.com/318788 and 334 // launching external applications via URLs. http://crbug.com/318788 and
259 // https://crbug.com/393481 335 // https://crbug.com/393481
260 if (frameType == WebURLRequest::FrameTypeNested && 336 if (frameType == WebURLRequest::FrameTypeNested &&
261 !SchemeRegistry::shouldTreatURLSchemeAsCORSEnabled(url.protocol())) 337 !SchemeRegistry::shouldTreatURLSchemeAsCORSEnabled(url.protocol()))
262 contextType = WebMixedContent::ContextType::OptionallyBlockable; 338 contextType = WebMixedContentContextType::OptionallyBlockable;
263 339
264 switch (contextType) { 340 switch (contextType) {
265 case WebMixedContent::ContextType::OptionallyBlockable: 341 case WebMixedContentContextType::OptionallyBlockable:
266 allowed = !strictMode; 342 allowed = !strictMode;
267 if (allowed) { 343 if (allowed) {
268 client->passiveInsecureContentFound(url); 344 client->passiveInsecureContentFound(url);
269 client->didDisplayInsecureContent(); 345 client->didDisplayInsecureContent();
270 } 346 }
271 break; 347 break;
272 348
273 case WebMixedContent::ContextType::Blockable: { 349 case WebMixedContentContextType::Blockable: {
274 // Strictly block subresources that are mixed with respect to their 350 // Strictly block subresources that are mixed with respect to their
275 // subframes, unless all insecure content is allowed. This is to avoid the 351 // subframes, unless all insecure content is allowed. This is to avoid the
276 // following situation: https://a.com embeds https://b.com, which loads a 352 // following situation: https://a.com embeds https://b.com, which loads a
277 // script over insecure HTTP. The user opts to allow the insecure content, 353 // script over insecure HTTP. The user opts to allow the insecure content,
278 // thinking that they are allowing an insecure script to run on 354 // thinking that they are allowing an insecure script to run on
279 // https://a.com and not realizing that they are in fact allowing an 355 // https://a.com and not realizing that they are in fact allowing an
280 // insecure script on https://b.com. 356 // insecure script on https://b.com.
281 if (!settings->getAllowRunningOfInsecureContent() && 357 if (!settings->getAllowRunningOfInsecureContent() &&
282 requestIsSubframeSubresource(effectiveFrame, frameType) && 358 requestIsSubframeSubresource(effectiveFrame, frameType) &&
283 isMixedContent(frame->securityContext()->getSecurityOrigin(), url)) { 359 isMixedContent(frame->securityContext()->getSecurityOrigin(), url)) {
(...skipping 11 matching lines...) Expand all
295 client->allowRunningInsecureContent( 371 client->allowRunningInsecureContent(
296 settings && settings->getAllowRunningOfInsecureContent(), 372 settings && settings->getAllowRunningOfInsecureContent(),
297 securityOrigin, url); 373 securityOrigin, url);
298 if (allowed) { 374 if (allowed) {
299 client->didRunInsecureContent(securityOrigin, url); 375 client->didRunInsecureContent(securityOrigin, url);
300 UseCounter::count(mixedFrame, UseCounter::MixedContentBlockableAllowed); 376 UseCounter::count(mixedFrame, UseCounter::MixedContentBlockableAllowed);
301 } 377 }
302 break; 378 break;
303 } 379 }
304 380
305 case WebMixedContent::ContextType::ShouldBeBlockable: 381 case WebMixedContentContextType::ShouldBeBlockable:
306 allowed = !strictMode; 382 allowed = !strictMode;
307 if (allowed) 383 if (allowed)
308 client->didDisplayInsecureContent(); 384 client->didDisplayInsecureContent();
309 break; 385 break;
310 case WebMixedContent::ContextType::NotMixedContent: 386 case WebMixedContentContextType::NotMixedContent:
311 NOTREACHED(); 387 NOTREACHED();
312 break; 388 break;
313 }; 389 };
314 390
315 if (reportingStatus == SendReport) { 391 if (reportingStatus == SendReport) {
316 logToConsoleAboutFetch(frame, mainResourceUrlForFrame(mixedFrame), url, 392 logToConsoleAboutFetch(frame, mainResourceUrlForFrame(mixedFrame), url,
317 requestContext, allowed); 393 requestContext, allowed);
318 } 394 }
319 return !allowed; 395 return !allowed;
320 } 396 }
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 Frame* effectiveFrame = effectiveFrameForFrameType(frame, frameType); 544 Frame* effectiveFrame = effectiveFrameForFrameType(frame, frameType);
469 if (frameType == WebURLRequest::FrameTypeTopLevel || !effectiveFrame) 545 if (frameType == WebURLRequest::FrameTypeTopLevel || !effectiveFrame)
470 return; 546 return;
471 547
472 // Use the current local frame's client; the embedder doesn't distinguish 548 // Use the current local frame's client; the embedder doesn't distinguish
473 // mixed content signals from different frames on the same page. 549 // mixed content signals from different frames on the same page.
474 FrameLoaderClient* client = frame->loader().client(); 550 FrameLoaderClient* client = frame->loader().client();
475 bool strictMixedContentCheckingForPlugin = 551 bool strictMixedContentCheckingForPlugin =
476 effectiveFrame->settings() && 552 effectiveFrame->settings() &&
477 effectiveFrame->settings()->getStrictMixedContentCheckingForPlugin(); 553 effectiveFrame->settings()->getStrictMixedContentCheckingForPlugin();
478 WebMixedContent::ContextType contextType = 554 WebMixedContentContextType contextType =
479 WebMixedContent::contextTypeFromRequestContext( 555 WebMixedContent::contextTypeFromRequestContext(
480 requestContext, strictMixedContentCheckingForPlugin); 556 requestContext, strictMixedContentCheckingForPlugin);
481 if (contextType == WebMixedContent::ContextType::Blockable) { 557 if (contextType == WebMixedContentContextType::Blockable) {
482 client->didRunContentWithCertificateErrors(response.url()); 558 client->didRunContentWithCertificateErrors(response.url());
483 } else { 559 } else {
484 // contextTypeFromRequestContext() never returns NotMixedContent (it 560 // contextTypeFromRequestContext() never returns NotMixedContent (it
485 // computes the type of mixed content, given that the content is mixed). 561 // computes the type of mixed content, given that the content is mixed).
486 DCHECK_NE(contextType, WebMixedContent::ContextType::NotMixedContent); 562 DCHECK_NE(contextType, WebMixedContentContextType::NotMixedContent);
487 client->didDisplayContentWithCertificateErrors(response.url()); 563 client->didDisplayContentWithCertificateErrors(response.url());
488 } 564 }
489 } 565 }
490 566
491 WebMixedContent::ContextType MixedContentChecker::contextTypeForInspector( 567 WebMixedContentContextType MixedContentChecker::contextTypeForInspector(
492 LocalFrame* frame, 568 LocalFrame* frame,
493 const ResourceRequest& request) { 569 const ResourceRequest& request) {
494 Frame* effectiveFrame = 570 Frame* effectiveFrame =
495 effectiveFrameForFrameType(frame, request.frameType()); 571 effectiveFrameForFrameType(frame, request.frameType());
496 572
497 Frame* mixedFrame = inWhichFrameIsContentMixed( 573 Frame* mixedFrame = inWhichFrameIsContentMixed(
498 effectiveFrame, request.frameType(), request.url()); 574 effectiveFrame, request.frameType(), request.url());
499 if (!mixedFrame) 575 if (!mixedFrame)
500 return WebMixedContent::ContextType::NotMixedContent; 576 return WebMixedContentContextType::NotMixedContent;
501 577
502 // See comment in shouldBlockFetch() about loading the main resource of a 578 // See comment in shouldBlockFetch() about loading the main resource of a
503 // subframe. 579 // subframe.
504 if (request.frameType() == WebURLRequest::FrameTypeNested && 580 if (request.frameType() == WebURLRequest::FrameTypeNested &&
505 !SchemeRegistry::shouldTreatURLSchemeAsCORSEnabled( 581 !SchemeRegistry::shouldTreatURLSchemeAsCORSEnabled(
506 request.url().protocol())) { 582 request.url().protocol())) {
507 return WebMixedContent::ContextType::OptionallyBlockable; 583 return WebMixedContentContextType::OptionallyBlockable;
508 } 584 }
509 585
510 bool strictMixedContentCheckingForPlugin = 586 bool strictMixedContentCheckingForPlugin =
511 mixedFrame->settings() && 587 mixedFrame->settings() &&
512 mixedFrame->settings()->getStrictMixedContentCheckingForPlugin(); 588 mixedFrame->settings()->getStrictMixedContentCheckingForPlugin();
513 return WebMixedContent::contextTypeFromRequestContext( 589 return WebMixedContent::contextTypeFromRequestContext(
514 request.requestContext(), strictMixedContentCheckingForPlugin); 590 request.requestContext(), strictMixedContentCheckingForPlugin);
515 } 591 }
516 592
517 } // namespace blink 593 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698