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

Unified Diff: third_party/WebKit/Source/core/loader/FrameLoader.cpp

Issue 2702503002: Block renderer-initiated main frame navigations to data URLs (Closed)
Patch Set: Fix Android PDF tests where PDFs should be downloaded Created 3 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/loader/FrameLoader.cpp
diff --git a/third_party/WebKit/Source/core/loader/FrameLoader.cpp b/third_party/WebKit/Source/core/loader/FrameLoader.cpp
index 79b097f9281ca8c90899efa8dee67898f64e100a..2e252351dd4255f658c349d2cd3a2030707ac3af 100644
--- a/third_party/WebKit/Source/core/loader/FrameLoader.cpp
+++ b/third_party/WebKit/Source/core/loader/FrameLoader.cpp
@@ -89,6 +89,7 @@
#include "platform/loader/fetch/ResourceFetcher.h"
#include "platform/loader/fetch/ResourceRequest.h"
#include "platform/network/HTTPParsers.h"
+#include "platform/network/NetworkUtils.h"
#include "platform/scroll/ScrollAnimatorBase.h"
#include "platform/weborigin/SchemeRegistry.h"
#include "platform/weborigin/SecurityOrigin.h"
@@ -805,6 +806,23 @@ bool FrameLoader::PrepareRequestForThisFrame(FrameLoadRequest& request) {
return false;
}
+ // Block renderer-initiated loads of data URLs in the top frame. If the mime
+ // type of the data URL is supported, the URL will eventually be rendered, so
+ // block it here. Otherwise, the load might be handled by a plugin or end up
+ // as a download, so allow it to let the embedder figure out what to do with
+ // it.
+ if (frame_->IsMainFrame() &&
+ !request.GetResourceRequest().IsSameDocumentNavigation() &&
+ !frame_->Client()->AllowContentInitiatedDataUrlNavigations(
+ request.OriginDocument()->Url()) &&
+ url.ProtocolIsData() && NetworkUtils::IsDataURLMimeTypeSupported(url)) {
+ frame_->GetDocument()->AddConsoleMessage(ConsoleMessage::Create(
+ kSecurityMessageSource, kErrorMessageLevel,
+ "Not allowed to navigate top frame to data URL: " +
+ url.ElidedString()));
+ return false;
+ }
+
if (!request.Form() && request.FrameName().IsEmpty())
request.SetFrameName(frame_->GetDocument()->BaseTarget());
return true;

Powered by Google App Engine
This is Rietveld 408576698