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

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

Issue 2702503002: Block renderer-initiated main frame navigations to data URLs (Closed)
Patch Set: nasko comments, fix most tests 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights
3 * reserved. 3 * reserved.
4 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 4 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
5 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. 5 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved.
6 * (http://www.torchmobile.com/) 6 * (http://www.torchmobile.com/)
7 * Copyright (C) 2008 Alp Toker <alp@atoker.com> 7 * Copyright (C) 2008 Alp Toker <alp@atoker.com>
8 * Copyright (C) Research In Motion Limited 2009. All rights reserved. 8 * Copyright (C) Research In Motion Limited 2009. All rights reserved.
9 * Copyright (C) 2011 Kris Jordan <krisjordan@gmail.com> 9 * Copyright (C) 2011 Kris Jordan <krisjordan@gmail.com>
10 * Copyright (C) 2011 Google Inc. All rights reserved. 10 * Copyright (C) 2011 Google Inc. All rights reserved.
(...skipping 865 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 876
877 KURL url = request.resourceRequest().url(); 877 KURL url = request.resourceRequest().url();
878 if (m_frame->script().executeScriptIfJavaScriptURL(url, nullptr)) 878 if (m_frame->script().executeScriptIfJavaScriptURL(url, nullptr))
879 return false; 879 return false;
880 880
881 if (!request.originDocument()->getSecurityOrigin()->canDisplay(url)) { 881 if (!request.originDocument()->getSecurityOrigin()->canDisplay(url)) {
882 reportLocalLoadFailed(m_frame, url.elidedString()); 882 reportLocalLoadFailed(m_frame, url.elidedString());
883 return false; 883 return false;
884 } 884 }
885 885
886 // Block content-initiated, top-frame navigations to data URLs. Allow if the
887 // top frame of the initiator is already a data URL so that links, redirects
888 // et.c. on data URLs aren't broken.
889 if (m_frame->isMainFrame() && url.protocol() == "data") {
890 // TODO: Check request()->downloadToFile()
891 bool canLoadDataURL = true;
892 if (request.originDocument()->frame()->tree().top()->isLocalFrame()) {
893 Document* topFrameDocument =
894 toLocalFrame(request.originDocument()->frame()->tree().top())
895 ->document();
896 canLoadDataURL =
897 topFrameDocument->url().protocol() == "data" ||
898 topFrameDocument->getSecurityOrigin()->canNavigateInTopFrame(url);
899 } else {
900 RemoteFrame* topFrame =
901 toRemoteFrame(request.originDocument()->frame()->tree().top());
902 // TODO(meacer): We don't know the URL of the remote frame, so this is
903 // only an estimate.
904 canLoadDataURL =
905 topFrame->securityContext()->getSecurityOrigin()->isUnique() ||
906 topFrame->securityContext()
907 ->getSecurityOrigin()
908 ->canNavigateInTopFrame(url);
909 }
910 if (!canLoadDataURL) {
911 reportTopLevelNavigationFailed(m_frame, url.elidedString());
912 return false;
913 }
914 }
915
886 if (!request.form() && request.frameName().isEmpty()) 916 if (!request.form() && request.frameName().isEmpty())
887 request.setFrameName(m_frame->document()->baseTarget()); 917 request.setFrameName(m_frame->document()->baseTarget());
888 return true; 918 return true;
889 } 919 }
890 920
891 static bool shouldNavigateTargetFrame(NavigationPolicy policy) { 921 static bool shouldNavigateTargetFrame(NavigationPolicy policy) {
892 switch (policy) { 922 switch (policy) {
893 case NavigationPolicyCurrentTab: 923 case NavigationPolicyCurrentTab:
894 return true; 924 return true;
895 925
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
1117 void FrameLoader::reportLocalLoadFailed(LocalFrame* frame, const String& url) { 1147 void FrameLoader::reportLocalLoadFailed(LocalFrame* frame, const String& url) {
1118 DCHECK(!url.isEmpty()); 1148 DCHECK(!url.isEmpty());
1119 if (!frame) 1149 if (!frame)
1120 return; 1150 return;
1121 1151
1122 frame->document()->addConsoleMessage( 1152 frame->document()->addConsoleMessage(
1123 ConsoleMessage::create(SecurityMessageSource, ErrorMessageLevel, 1153 ConsoleMessage::create(SecurityMessageSource, ErrorMessageLevel,
1124 "Not allowed to load local resource: " + url)); 1154 "Not allowed to load local resource: " + url));
1125 } 1155 }
1126 1156
1157 void FrameLoader::reportTopLevelNavigationFailed(LocalFrame* frame,
1158 const String& url) {
1159 DCHECK(!url.isEmpty());
1160 if (!frame)
1161 return;
1162
1163 frame->document()->addConsoleMessage(ConsoleMessage::create(
1164 SecurityMessageSource, ErrorMessageLevel,
1165 "Not allowed to top-level navigate to resource: " + url));
1166 }
1167
1127 void FrameLoader::stopAllLoaders() { 1168 void FrameLoader::stopAllLoaders() {
1128 if (m_frame->document()->pageDismissalEventBeingDispatched() != 1169 if (m_frame->document()->pageDismissalEventBeingDispatched() !=
1129 Document::NoDismissal) 1170 Document::NoDismissal)
1130 return; 1171 return;
1131 1172
1132 // If this method is called from within this method, infinite recursion can 1173 // If this method is called from within this method, infinite recursion can
1133 // occur (3442218). Avoid this. 1174 // occur (3442218). Avoid this.
1134 if (m_inStopAllLoaders) 1175 if (m_inStopAllLoaders)
1135 return; 1176 return;
1136 1177
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after
1901 frameLoadRequest.clientRedirect()); 1942 frameLoadRequest.clientRedirect());
1902 1943
1903 loader->setLoadType(loadType); 1944 loader->setLoadType(loadType);
1904 loader->setNavigationType(navigationType); 1945 loader->setNavigationType(navigationType);
1905 loader->setReplacesCurrentHistoryItem(loadType == 1946 loader->setReplacesCurrentHistoryItem(loadType ==
1906 FrameLoadTypeReplaceCurrentItem); 1947 FrameLoadTypeReplaceCurrentItem);
1907 return loader; 1948 return loader;
1908 } 1949 }
1909 1950
1910 } // namespace blink 1951 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698