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

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

Issue 2198933003: Prevent mixed content iframes on back/forward. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 // Use the current local frame's client; the embedder doesn't 196 // Use the current local frame's client; the embedder doesn't
197 // distinguish mixed content signals from different frames on the 197 // distinguish mixed content signals from different frames on the
198 // same page. 198 // same page.
199 FrameLoaderClient* client = frame->loader().client(); 199 FrameLoaderClient* client = frame->loader().client();
200 SecurityOrigin* securityOrigin = mixedFrame->securityContext()->getSecurityO rigin(); 200 SecurityOrigin* securityOrigin = mixedFrame->securityContext()->getSecurityO rigin();
201 bool allowed = false; 201 bool allowed = false;
202 202
203 // If we're in strict mode, we'll automagically fail everything, and intenti onally skip 203 // If we're in strict mode, we'll automagically fail everything, and intenti onally skip
204 // the client checks in order to prevent degrading the site's security UI. 204 // the client checks in order to prevent degrading the site's security UI.
205 bool strictMode = mixedFrame->securityContext()->getInsecureRequestPolicy() & kBlockAllMixedContent || settings->strictMixedContentChecking(); 205 bool strictMode = mixedFrame->securityContext()->getInsecureRequestPolicy() & kBlockAllMixedContent || settings->strictMixedContentChecking();
206 DLOG(INFO) << "MCC:shouldBlockFetch for "<< url.getString() << ", strictMode ? " << strictMode <<
207 ", requestContext: " << requestContext;
Charlie Reis 2016/08/01 23:39:16 Ignore all these DLOGs-- I'll remove them before w
206 208
207 WebMixedContent::ContextType contextType = WebMixedContent::contextTypeFromR equestContext(requestContext, settings->strictMixedContentCheckingForPlugin()); 209 WebMixedContent::ContextType contextType = WebMixedContent::contextTypeFromR equestContext(requestContext, settings->strictMixedContentCheckingForPlugin());
208 210
209 // If we're loading the main resource of a subframe, we need to take a close look at the loaded URL. 211 // If we're loading the main resource of a subframe, we need to take a close look at the loaded URL.
210 // If we're dealing with a CORS-enabled scheme, then block mixed frames as a ctive content. Otherwise, 212 // If we're dealing with a CORS-enabled scheme, then block mixed frames as a ctive content. Otherwise,
211 // treat frames as passive content. 213 // treat frames as passive content.
212 // 214 //
213 // FIXME: Remove this temporary hack once we have a reasonable API for launc hing external applications 215 // FIXME: Remove this temporary hack once we have a reasonable API for launc hing external applications
214 // via URLs. http://crbug.com/318788 and https://crbug.com/393481 216 // via URLs. http://crbug.com/318788 and https://crbug.com/393481
215 if (frameType == WebURLRequest::FrameTypeNested && !SchemeRegistry::shouldTr eatURLSchemeAsCORSEnabled(url.protocol())) 217 if (frameType == WebURLRequest::FrameTypeNested && !SchemeRegistry::shouldTr eatURLSchemeAsCORSEnabled(url.protocol()))
216 contextType = WebMixedContent::ContextType::OptionallyBlockable; 218 contextType = WebMixedContent::ContextType::OptionallyBlockable;
217 219
218 switch (contextType) { 220 switch (contextType) {
219 case WebMixedContent::ContextType::OptionallyBlockable: 221 case WebMixedContent::ContextType::OptionallyBlockable:
220 allowed = !strictMode && client->allowDisplayingInsecureContent(settings && settings->allowDisplayOfInsecureContent(), url); 222 allowed = !strictMode && client->allowDisplayingInsecureContent(settings && settings->allowDisplayOfInsecureContent(), url);
223 DLOG(INFO) << "MCC: OptionallyBlockable says " << allowed;
221 if (allowed) 224 if (allowed)
222 client->didDisplayInsecureContent(); 225 client->didDisplayInsecureContent();
223 break; 226 break;
224 227
225 case WebMixedContent::ContextType::Blockable: { 228 case WebMixedContent::ContextType::Blockable: {
226 // Strictly block subresources that are mixed with respect to 229 // Strictly block subresources that are mixed with respect to
227 // their subframes, unless all insecure content is allowed. This 230 // their subframes, unless all insecure content is allowed. This
228 // is to avoid the following situation: https://a.com embeds 231 // is to avoid the following situation: https://a.com embeds
229 // https://b.com, which loads a script over insecure HTTP. The 232 // https://b.com, which loads a script over insecure HTTP. The
230 // user opts to allow the insecure content, thinking that they are 233 // user opts to allow the insecure content, thinking that they are
231 // allowing an insecure script to run on https://a.com and not 234 // allowing an insecure script to run on https://a.com and not
232 // realizing that they are in fact allowing an insecure script on 235 // realizing that they are in fact allowing an insecure script on
233 // https://b.com. 236 // https://b.com.
237 DLOG(INFO) << "MCC: Blockable...";
234 if (!settings->allowRunningOfInsecureContent() && requestIsSubframeSubre source(effectiveFrame, frameType) && isMixedContent(frame->securityContext()->ge tSecurityOrigin(), url)) { 238 if (!settings->allowRunningOfInsecureContent() && requestIsSubframeSubre source(effectiveFrame, frameType) && isMixedContent(frame->securityContext()->ge tSecurityOrigin(), url)) {
239 DLOG(INFO) << "MCC: Settings says not allowed.";
235 UseCounter::count(mixedFrame, UseCounter::BlockableMixedContentInSub frameBlocked); 240 UseCounter::count(mixedFrame, UseCounter::BlockableMixedContentInSub frameBlocked);
236 allowed = false; 241 allowed = false;
237 break; 242 break;
238 } 243 }
239 244
240 bool shouldAskEmbedder = !strictMode && settings && (!settings->strictly BlockBlockableMixedContent() || settings->allowRunningOfInsecureContent()); 245 bool shouldAskEmbedder = !strictMode && settings && (!settings->strictly BlockBlockableMixedContent() || settings->allowRunningOfInsecureContent());
241 allowed = shouldAskEmbedder && client->allowRunningInsecureContent(setti ngs && settings->allowRunningOfInsecureContent(), securityOrigin, url); 246 allowed = shouldAskEmbedder && client->allowRunningInsecureContent(setti ngs && settings->allowRunningOfInsecureContent(), securityOrigin, url);
247 DLOG(INFO) << "MCC: shouldAskEmbedder: " << shouldAskEmbedder << ", allo wed: " << allowed;
242 if (allowed) { 248 if (allowed) {
249 DLOG(INFO) << "MCC: Client says allowed.";
243 client->didRunInsecureContent(securityOrigin, url); 250 client->didRunInsecureContent(securityOrigin, url);
244 UseCounter::count(mixedFrame, UseCounter::MixedContentBlockableAllow ed); 251 UseCounter::count(mixedFrame, UseCounter::MixedContentBlockableAllow ed);
245 } 252 }
246 break; 253 break;
247 } 254 }
248 255
249 case WebMixedContent::ContextType::ShouldBeBlockable: 256 case WebMixedContent::ContextType::ShouldBeBlockable:
257 DLOG(INFO) << "MCC: ShouldBeBlockable";
250 allowed = !strictMode; 258 allowed = !strictMode;
251 if (allowed) 259 if (allowed)
252 client->didDisplayInsecureContent(); 260 client->didDisplayInsecureContent();
253 break; 261 break;
254 case WebMixedContent::ContextType::NotMixedContent: 262 case WebMixedContent::ContextType::NotMixedContent:
255 NOTREACHED(); 263 NOTREACHED();
256 break; 264 break;
257 }; 265 };
258 266
267 DLOG(INFO) << "MCC: allowed: " << allowed;
259 if (reportingStatus == SendReport) 268 if (reportingStatus == SendReport)
260 logToConsoleAboutFetch(frame, mainResourceUrlForFrame(mixedFrame), url, requestContext, allowed); 269 logToConsoleAboutFetch(frame, mainResourceUrlForFrame(mixedFrame), url, requestContext, allowed);
261 return !allowed; 270 return !allowed;
262 } 271 }
263 272
264 // static 273 // static
265 void MixedContentChecker::logToConsoleAboutWebSocket(LocalFrame* frame, const KU RL& mainResourceUrl, const KURL& url, bool allowed) 274 void MixedContentChecker::logToConsoleAboutWebSocket(LocalFrame* frame, const KU RL& mainResourceUrl, const KURL& url, bool allowed)
266 { 275 {
267 String message = String::format( 276 String message = String::format(
268 "Mixed Content: The page at '%s' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint '%s'. %s", 277 "Mixed Content: The page at '%s' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint '%s'. %s",
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 // See comment in shouldBlockFetch() about loading the main resource of a su bframe. 402 // See comment in shouldBlockFetch() about loading the main resource of a su bframe.
394 if (request.frameType() == WebURLRequest::FrameTypeNested && !SchemeRegistry ::shouldTreatURLSchemeAsCORSEnabled(request.url().protocol())) { 403 if (request.frameType() == WebURLRequest::FrameTypeNested && !SchemeRegistry ::shouldTreatURLSchemeAsCORSEnabled(request.url().protocol())) {
395 return WebMixedContent::ContextType::OptionallyBlockable; 404 return WebMixedContent::ContextType::OptionallyBlockable;
396 } 405 }
397 406
398 bool strictMixedContentCheckingForPlugin = mixedFrame->settings() && mixedFr ame->settings()->strictMixedContentCheckingForPlugin(); 407 bool strictMixedContentCheckingForPlugin = mixedFrame->settings() && mixedFr ame->settings()->strictMixedContentCheckingForPlugin();
399 return WebMixedContent::contextTypeFromRequestContext(request.requestContext (), strictMixedContentCheckingForPlugin); 408 return WebMixedContent::contextTypeFromRequestContext(request.requestContext (), strictMixedContentCheckingForPlugin);
400 } 409 }
401 410
402 } // namespace blink 411 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698