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

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

Issue 1617043002: Introduce AncestorThrottle, which will process 'X-Frame-Options' headers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@block-response
Patch Set: Drop XFO from Blink. Created 4 years, 8 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 , m_fetcher(FrameFetchContext::createContextAndFetcher(this, nullptr)) 100 , m_fetcher(FrameFetchContext::createContextAndFetcher(this, nullptr))
101 , m_originalRequest(req) 101 , m_originalRequest(req)
102 , m_substituteData(substituteData) 102 , m_substituteData(substituteData)
103 , m_request(req) 103 , m_request(req)
104 , m_isClientRedirect(false) 104 , m_isClientRedirect(false)
105 , m_replacesCurrentHistoryItem(false) 105 , m_replacesCurrentHistoryItem(false)
106 , m_navigationType(NavigationTypeOther) 106 , m_navigationType(NavigationTypeOther)
107 , m_documentLoadTiming(*this) 107 , m_documentLoadTiming(*this)
108 , m_timeOfLastDataReceived(0.0) 108 , m_timeOfLastDataReceived(0.0)
109 , m_applicationCacheHost(ApplicationCacheHost::create(this)) 109 , m_applicationCacheHost(ApplicationCacheHost::create(this))
110 , m_wasBlockedAfterXFrameOptionsOrCSP(false) 110 , m_wasBlockedAfterCSP(false)
111 , m_state(NotStarted) 111 , m_state(NotStarted)
112 , m_inDataReceived(false) 112 , m_inDataReceived(false)
113 , m_dataBuffer(SharedBuffer::create()) 113 , m_dataBuffer(SharedBuffer::create())
114 { 114 {
115 } 115 }
116 116
117 FrameLoader* DocumentLoader::frameLoader() const 117 FrameLoader* DocumentLoader::frameLoader() const
118 { 118 {
119 if (!m_frame) 119 if (!m_frame)
120 return nullptr; 120 return nullptr;
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 // Downloading is handled by the embedder, but we still get the initial 343 // Downloading is handled by the embedder, but we still get the initial
344 // response so that we can ignore it and clean up properly. 344 // response so that we can ignore it and clean up properly.
345 return false; 345 return false;
346 } 346 }
347 347
348 if (!canShowMIMEType(m_response.mimeType(), m_frame->page())) 348 if (!canShowMIMEType(m_response.mimeType(), m_frame->page()))
349 return false; 349 return false;
350 return true; 350 return true;
351 } 351 }
352 352
353 void DocumentLoader::cancelLoadAfterXFrameOptionsOrCSPDenied(const ResourceRespo nse& response) 353 void DocumentLoader::cancelLoadAfterCSPDenied(const ResourceResponse& response)
354 { 354 {
355 InspectorInstrumentation::continueAfterXFrameOptionsDenied(m_frame, this, ma inResourceIdentifier(), response); 355 InspectorInstrumentation::continueAfterCSPDenied(m_frame, this, mainResource Identifier(), response);
356 356
357 setWasBlockedAfterXFrameOptionsOrCSP(); 357 setWasBlockedAfterCSP();
358 358
359 // Pretend that this was an empty HTTP 200 response. 359 // Pretend that this was an empty HTTP 200 response.
360 clearMainResourceHandle(); 360 clearMainResourceHandle();
361 m_response = ResourceResponse(blankURL(), "text/html", 0, nullAtom, String() ); 361 m_response = ResourceResponse(blankURL(), "text/html", 0, nullAtom, String() );
362 finishedLoading(monotonicallyIncreasingTime()); 362 finishedLoading(monotonicallyIncreasingTime());
363 363
364 return; 364 return;
365 } 365 }
366 366
367 void DocumentLoader::responseReceived(Resource* resource, const ResourceResponse & response, PassOwnPtr<WebDataConsumerHandle> handle) 367 void DocumentLoader::responseReceived(Resource* resource, const ResourceResponse & response, PassOwnPtr<WebDataConsumerHandle> handle)
368 { 368 {
369 ASSERT_UNUSED(resource, m_mainResource == resource); 369 ASSERT_UNUSED(resource, m_mainResource == resource);
370 ASSERT_UNUSED(handle, !handle); 370 ASSERT_UNUSED(handle, !handle);
371 ASSERT(frame()); 371 ASSERT(frame());
372 372
373 m_applicationCacheHost->didReceiveResponseForMainResource(response); 373 m_applicationCacheHost->didReceiveResponseForMainResource(response);
374 374
375 // The memory cache doesn't understand the application cache or its caching rules. So if a main resource is served 375 // The memory cache doesn't understand the application cache or its caching rules. So if a main resource is served
376 // from the application cache, ensure we don't save the result for future us e. All responses loaded 376 // from the application cache, ensure we don't save the result for future us e. All responses loaded
377 // from appcache will have a non-zero appCacheID(). 377 // from appcache will have a non-zero appCacheID().
378 if (response.appCacheID()) 378 if (response.appCacheID())
379 memoryCache()->remove(m_mainResource.get()); 379 memoryCache()->remove(m_mainResource.get());
380 380
381 m_contentSecurityPolicy = ContentSecurityPolicy::create(); 381 m_contentSecurityPolicy = ContentSecurityPolicy::create();
382 m_contentSecurityPolicy->setOverrideURLForSelf(response.url()); 382 m_contentSecurityPolicy->setOverrideURLForSelf(response.url());
383 m_contentSecurityPolicy->didReceiveHeaders(ContentSecurityPolicyResponseHead ers(response)); 383 m_contentSecurityPolicy->didReceiveHeaders(ContentSecurityPolicyResponseHead ers(response));
384 if (!m_contentSecurityPolicy->allowAncestors(m_frame, response.url())) { 384 if (!m_contentSecurityPolicy->allowAncestors(m_frame, response.url())) {
385 cancelLoadAfterXFrameOptionsOrCSPDenied(response); 385 cancelLoadAfterCSPDenied(response);
386 return; 386 return;
387 } 387 }
388 388
389 // 'frame-ancestors' obviates 'x-frame-options': https://w3c.github.io/webap psec/specs/content-security-policy/#frame-ancestors-and-frame-options
390 if (!m_contentSecurityPolicy->isFrameAncestorsEnforced()) {
391 HTTPHeaderMap::const_iterator it = response.httpHeaderFields().find(HTTP Names::X_Frame_Options);
392 if (it != response.httpHeaderFields().end()) {
393 String content = it->value;
394 if (frameLoader()->shouldInterruptLoadForXFrameOptions(content, resp onse.url(), mainResourceIdentifier())) {
395 String message = "Refused to display '" + response.url().elidedS tring() + "' in a frame because it set 'X-Frame-Options' to '" + content + "'.";
396 ConsoleMessage* consoleMessage = ConsoleMessage::create(Security MessageSource, ErrorMessageLevel, message);
397 consoleMessage->setRequestIdentifier(mainResourceIdentifier());
398 frame()->document()->addConsoleMessage(consoleMessage);
399
400 cancelLoadAfterXFrameOptionsOrCSPDenied(response);
401 return;
402 }
403 }
404 }
405
406 ASSERT(!m_frame->page()->defersLoading()); 389 ASSERT(!m_frame->page()->defersLoading());
407 390
408 m_response = response; 391 m_response = response;
409 392
410 if (isArchiveMIMEType(m_response.mimeType()) && m_mainResource->getDataBuffe ringPolicy() != BufferData) 393 if (isArchiveMIMEType(m_response.mimeType()) && m_mainResource->getDataBuffe ringPolicy() != BufferData)
411 m_mainResource->setDataBufferingPolicy(BufferData); 394 m_mainResource->setDataBufferingPolicy(BufferData);
412 395
413 if (!shouldContinueForResponse()) { 396 if (!shouldContinueForResponse()) {
414 InspectorInstrumentation::continueWithPolicyIgnore(m_frame, this, m_main Resource->identifier(), m_response); 397 InspectorInstrumentation::continueWithPolicyIgnore(m_frame, this, m_main Resource->identifier(), m_response);
415 m_fetcher->stopFetching(); 398 m_fetcher->stopFetching();
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
685 { 668 {
686 m_writer = createWriterFor(init, mimeType(), m_writer ? m_writer->encoding() : emptyAtom, true, ForceSynchronousParsing); 669 m_writer = createWriterFor(init, mimeType(), m_writer ? m_writer->encoding() : emptyAtom, true, ForceSynchronousParsing);
687 if (!source.isNull()) 670 if (!source.isNull())
688 m_writer->appendReplacingData(source); 671 m_writer->appendReplacingData(source);
689 endWriting(m_writer.get()); 672 endWriting(m_writer.get());
690 } 673 }
691 674
692 DEFINE_WEAK_IDENTIFIER_MAP(DocumentLoader); 675 DEFINE_WEAK_IDENTIFIER_MAP(DocumentLoader);
693 676
694 } // namespace blink 677 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698