Commit aa36b98f authored by Jochen Eisinger's avatar Jochen Eisinger Committed by Commit Bot

Drop the suggested name of downloads when initiator & resource origin differ

Compare https://html.spec.whatwg.org/#downloading-resources step 3-9.

BUG=714373
R=dtrainor@chromium.org

Change-Id: Iae9831c488fac56442ebf608203853da022fdf10
Reviewed-on: https://chromium-review.googlesource.com/509253
Commit-Queue: Jochen Eisinger <jochen@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#473428}
parent dcc699ff
...@@ -337,14 +337,15 @@ bool DownloadRequestCore::OnResponseStarted( ...@@ -337,14 +337,15 @@ bool DownloadRequestCore::OnResponseStarted(
headers->HasHeaderValue("Accept-Ranges", "bytes"); headers->HasHeaderValue("Accept-Ranges", "bytes");
} }
// Blink verifies that the requester of this download is allowed to set a // GURL::GetOrigin() doesn't support getting the inner origin of a blob URL.
// suggested name for the security origin of the download URL. However, this // However, requesting a cross origin blob URL would have resulted in a
// assumption doesn't hold if there were cross origin redirects. Therefore, // network error, so we'll just ignore them here.
// clear the suggested_name for such requests. if (request()->initiator().has_value() &&
if (create_info->url_chain.size() > 1 && !create_info->url_chain.back().SchemeIsBlob() &&
create_info->url_chain.front().GetOrigin() != request()->initiator()->GetURL() !=
create_info->url_chain.back().GetOrigin()) create_info->url_chain.back().GetOrigin()) {
create_info->save_info->suggested_name.clear(); create_info->save_info->suggested_name.clear();
}
RecordDownloadContentDisposition(create_info->content_disposition); RecordDownloadContentDisposition(create_info->content_disposition);
RecordDownloadSourcePageTransitionType(create_info->transition_type); RecordDownloadSourcePageTransitionType(create_info->transition_type);
......
Downloading URL with suggested filename "" Downloading URL with suggested filename "foo.pdf"
Tests that a suggested filename on a download attribute is ignored if the link is cross origin. Tests that a suggested filename on a download attribute is passed along even if the link is cross origin.
The suggested filename at the top should be empty. The suggested filename at the top should be non-empty. The actual cross-origin check will be done in the browser process.
...@@ -11,10 +11,11 @@ if (window.testRunner) { ...@@ -11,10 +11,11 @@ if (window.testRunner) {
</head> </head>
<body> <body>
<p> <p>
Tests that a suggested filename on a download attribute is ignored if Tests that a suggested filename on a download attribute is passed along even if
<a id="dl" href="http://localhost:8080/security/resources/attachment.php" download="foo.pdf">the link</a> is cross origin. <a id="dl" href="http://localhost:8080/security/resources/attachment.php" download="foo.pdf">the link</a> is cross origin.
<p> <p>
The suggested filename at the top should be empty. The suggested filename at the top should be non-empty. The actual cross-origin
check will be done in the browser process.
<script> <script>
function click(elmt) function click(elmt)
{ {
......
...@@ -360,15 +360,11 @@ void HTMLAnchorElement::HandleClick(Event* event) { ...@@ -360,15 +360,11 @@ void HTMLAnchorElement::HandleClick(Event* event) {
if (hasAttribute(downloadAttr)) { if (hasAttribute(downloadAttr)) {
request.SetRequestContext(WebURLRequest::kRequestContextDownload); request.SetRequestContext(WebURLRequest::kRequestContextDownload);
bool is_same_origin =
completed_url.ProtocolIsData() ||
GetDocument().GetSecurityOrigin()->CanRequest(completed_url);
const AtomicString& suggested_name =
(is_same_origin ? FastGetAttribute(downloadAttr) : g_null_atom);
request.SetRequestorOrigin(SecurityOrigin::Create(GetDocument().Url())); request.SetRequestorOrigin(SecurityOrigin::Create(GetDocument().Url()));
frame->Loader().Client()->LoadURLExternally( frame->Loader().Client()->LoadURLExternally(
request, kNavigationPolicyDownload, suggested_name, false); request, kNavigationPolicyDownload, FastGetAttribute(downloadAttr),
false);
} else { } else {
request.SetRequestContext(WebURLRequest::kRequestContextHyperlink); request.SetRequestContext(WebURLRequest::kRequestContextHyperlink);
FrameLoadRequest frame_request(&GetDocument(), request, FrameLoadRequest frame_request(&GetDocument(), request,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment