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

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

Issue 2702503002: Block renderer-initiated main frame navigations to data URLs (Closed)
Patch Set: kinuko comments 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 8cd77648a4dd0116286c5cf0df7be66d44d27041..7203ef8a2cfd4b84370797a8c79ef740909036aa 100644
--- a/third_party/WebKit/Source/core/loader/FrameLoader.cpp
+++ b/third_party/WebKit/Source/core/loader/FrameLoader.cpp
@@ -748,6 +748,17 @@ bool FrameLoader::PrepareRequestForThisFrame(FrameLoadRequest& request) {
return false;
}
+ // Block content-initiated, top-frame navigations to data URLs.
+ if (frame_->IsMainFrame() &&
+ !request.GetResourceRequest().IsSameDocumentNavigation() &&
+ !frame_->Client()->AllowContentInitiatedDataUrlNavigations(
+ request.OriginDocument()->Url()) &&
+ !request.OriginDocument()->GetSecurityOrigin()->CanNavigateInTopFrame(
+ url)) {
+ ReportTopLevelNavigationFailed(frame_, url.ElidedString());
+ return false;
+ }
+
if (!request.Form() && request.FrameName().IsEmpty())
request.SetFrameName(frame_->GetDocument()->BaseTarget());
return true;
@@ -987,6 +998,17 @@ void FrameLoader::ReportLocalLoadFailed(LocalFrame* frame, const String& url) {
"Not allowed to load local resource: " + url));
}
+void FrameLoader::ReportTopLevelNavigationFailed(LocalFrame* frame,
+ const String& url) {
+ DCHECK(!url.IsEmpty());
+ if (!frame)
+ return;
+
+ frame->GetDocument()->AddConsoleMessage(ConsoleMessage::Create(
+ kSecurityMessageSource, kErrorMessageLevel,
+ "Not allowed to top-level navigate to resource: " + url));
+}
+
void FrameLoader::StopAllLoaders() {
if (frame_->GetDocument()->PageDismissalEventBeingDispatched() !=
Document::kNoDismissal)

Powered by Google App Engine
This is Rietveld 408576698