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

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

Issue 1326823003: CSP: 'frame-ancestors' should override 'x-frame-options'. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2011 Google Inc. All rights reserved. 3 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 ASSERT(frame()); 462 ASSERT(frame());
463 463
464 m_applicationCacheHost->didReceiveResponseForMainResource(response); 464 m_applicationCacheHost->didReceiveResponseForMainResource(response);
465 465
466 // The memory cache doesn't understand the application cache or its caching rules. So if a main resource is served 466 // The memory cache doesn't understand the application cache or its caching rules. So if a main resource is served
467 // from the application cache, ensure we don't save the result for future us e. All responses loaded 467 // from the application cache, ensure we don't save the result for future us e. All responses loaded
468 // from appcache will have a non-zero appCacheID(). 468 // from appcache will have a non-zero appCacheID().
469 if (response.appCacheID()) 469 if (response.appCacheID())
470 memoryCache()->remove(m_mainResource.get()); 470 memoryCache()->remove(m_mainResource.get());
471 471
472 DEFINE_STATIC_LOCAL(AtomicString, xFrameOptionHeader, ("x-frame-options", At omicString::ConstructFromLiteral));
473 HTTPHeaderMap::const_iterator it = response.httpHeaderFields().find(xFrameOp tionHeader);
474 if (it != response.httpHeaderFields().end()) {
475 String content = it->value;
476 if (frameLoader()->shouldInterruptLoadForXFrameOptions(content, response .url(), mainResourceIdentifier())) {
477 String message = "Refused to display '" + response.url().elidedStrin g() + "' in a frame because it set 'X-Frame-Options' to '" + content + "'.";
478 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage:: create(SecurityMessageSource, ErrorMessageLevel, message);
479 consoleMessage->setRequestIdentifier(mainResourceIdentifier());
480 frame()->document()->addConsoleMessage(consoleMessage.release());
481
482 cancelLoadAfterXFrameOptionsOrCSPDenied(response);
483 return;
484 }
485 }
486
487 m_contentSecurityPolicy = ContentSecurityPolicy::create(); 472 m_contentSecurityPolicy = ContentSecurityPolicy::create();
488 m_contentSecurityPolicy->setOverrideURLForSelf(response.url()); 473 m_contentSecurityPolicy->setOverrideURLForSelf(response.url());
489 m_contentSecurityPolicy->didReceiveHeaders(ContentSecurityPolicyResponseHead ers(response)); 474 m_contentSecurityPolicy->didReceiveHeaders(ContentSecurityPolicyResponseHead ers(response));
490 if (!m_contentSecurityPolicy->allowAncestors(m_frame, response.url())) { 475 if (!m_contentSecurityPolicy->allowAncestors(m_frame, response.url())) {
491 cancelLoadAfterXFrameOptionsOrCSPDenied(response); 476 cancelLoadAfterXFrameOptionsOrCSPDenied(response);
492 return; 477 return;
493 } 478 }
494 479
480 DEFINE_STATIC_LOCAL(AtomicString, xFrameOptionHeader, ("x-frame-options", At omicString::ConstructFromLiteral));
481
482 // 'frame-ancestors' obviates 'x-frame-options': https://w3c.github.io/webap psec/specs/content-security-policy/#frame-ancestors-and-frame-options
483 if (!m_contentSecurityPolicy->isFrameAncestorsEnforced()) {
484 HTTPHeaderMap::const_iterator it = response.httpHeaderFields().find(xFra meOptionHeader);
485 if (it != response.httpHeaderFields().end()) {
486 String content = it->value;
487 if (frameLoader()->shouldInterruptLoadForXFrameOptions(content, resp onse.url(), mainResourceIdentifier())) {
488 String message = "Refused to display '" + response.url().elidedS tring() + "' in a frame because it set 'X-Frame-Options' to '" + content + "'.";
489 RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessa ge::create(SecurityMessageSource, ErrorMessageLevel, message);
490 consoleMessage->setRequestIdentifier(mainResourceIdentifier());
491 frame()->document()->addConsoleMessage(consoleMessage.release()) ;
492
493 cancelLoadAfterXFrameOptionsOrCSPDenied(response);
494 return;
495 }
496 }
497 }
498
495 ASSERT(!mainResourceLoader() || !mainResourceLoader()->defersLoading()); 499 ASSERT(!mainResourceLoader() || !mainResourceLoader()->defersLoading());
496 500
497 m_response = response; 501 m_response = response;
498 502
499 if (isArchiveMIMEType(m_response.mimeType()) && m_mainResource->dataBufferin gPolicy() != BufferData) 503 if (isArchiveMIMEType(m_response.mimeType()) && m_mainResource->dataBufferin gPolicy() != BufferData)
500 m_mainResource->setDataBufferingPolicy(BufferData); 504 m_mainResource->setDataBufferingPolicy(BufferData);
501 505
502 if (!shouldContinueForResponse()) { 506 if (!shouldContinueForResponse()) {
503 InspectorInstrumentation::continueWithPolicyIgnore(m_frame, this, m_main Resource->identifier(), m_response); 507 InspectorInstrumentation::continueWithPolicyIgnore(m_frame, this, m_main Resource->identifier(), m_response);
504 cancelMainResourceLoad(ResourceError::cancelledError(m_request.url())); 508 cancelMainResourceLoad(ResourceError::cancelledError(m_request.url()));
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 { 869 {
866 m_writer = createWriterFor(ownerDocument, init, mimeType(), m_writer ? m_wri ter->encoding() : emptyAtom, true, ForceSynchronousParsing); 870 m_writer = createWriterFor(ownerDocument, init, mimeType(), m_writer ? m_wri ter->encoding() : emptyAtom, true, ForceSynchronousParsing);
867 if (!source.isNull()) 871 if (!source.isNull())
868 m_writer->appendReplacingData(source); 872 m_writer->appendReplacingData(source);
869 endWriting(m_writer.get()); 873 endWriting(m_writer.get());
870 } 874 }
871 875
872 DEFINE_WEAK_IDENTIFIER_MAP(DocumentLoader); 876 DEFINE_WEAK_IDENTIFIER_MAP(DocumentLoader);
873 877
874 } // namespace blink 878 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698