- Revision
- 206478
- Author
- cdu...@apple.com
- Date
- 2016-09-27 17:37:01 -0700 (Tue, 27 Sep 2016)
Log Message
<a download> does not honor the same-origin requirement
https://bugs.webkit.org/show_bug.cgi?id=156100
Reviewed by Alex Christensen.
Source/WebCore:
We now completely ignore the "download" attribute on anchors if the
href URL is cross-origin. We therefore navigate to the URL instead
of forcefully downloading it in this case and leave it up to the server
to give us the right headers if it should be downloaded. This is
conservative and matches Firefox.
Chrome and the HTML specification ignore only the suggested filename
if the URL is cross-origin but still download the file.
No new tests, updated existing test.
* html/HTMLAnchorElement.cpp:
(WebCore::HTMLAnchorElement::handleClick):
LayoutTests:
Update existing cross origin test as it expected the suggested filename to
be ignored but the file to still be downloaded (Chrome behavior) instead
of the download attribute to be completely ignored and therefore navigate
(Firefox behavior).
* TestExpectations:
* http/tests/resources/pass-notify-done.html: Added.
* http/tests/security/anchor-download-block-crossorigin-expected.txt:
* http/tests/security/anchor-download-block-crossorigin.html:
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (206477 => 206478)
--- trunk/LayoutTests/ChangeLog 2016-09-28 00:31:44 UTC (rev 206477)
+++ trunk/LayoutTests/ChangeLog 2016-09-28 00:37:01 UTC (rev 206478)
@@ -1,3 +1,20 @@
+2016-09-27 Chris Dumez <cdu...@apple.com>
+
+ <a download> does not honor the same-origin requirement
+ https://bugs.webkit.org/show_bug.cgi?id=156100
+
+ Reviewed by Alex Christensen.
+
+ Update existing cross origin test as it expected the suggested filename to
+ be ignored but the file to still be downloaded (Chrome behavior) instead
+ of the download attribute to be completely ignored and therefore navigate
+ (Firefox behavior).
+
+ * TestExpectations:
+ * http/tests/resources/pass-notify-done.html: Added.
+ * http/tests/security/anchor-download-block-crossorigin-expected.txt:
+ * http/tests/security/anchor-download-block-crossorigin.html:
+
2016-09-27 Ryan Haddad <ryanhad...@apple.com>
Marking http/tests/xmlhttprequest/onabort-response-getters.html as failing on Sierra.
Modified: trunk/LayoutTests/TestExpectations (206477 => 206478)
--- trunk/LayoutTests/TestExpectations 2016-09-28 00:31:44 UTC (rev 206477)
+++ trunk/LayoutTests/TestExpectations 2016-09-28 00:37:01 UTC (rev 206478)
@@ -898,9 +898,6 @@
fast/scrolling/rtl-scrollbars-alternate-iframe-body-dir-attr-does-not-update-scrollbar-placement.html [ ImageOnlyFailure ]
fast/scrolling/rtl-scrollbars-animation-property.html [ Failure ]
-# <a download> does not honor cross-origin restrictions
-webkit.org/b/156100 http/tests/security/anchor-download-block-crossorigin.html [ Failure ]
-
webkit.org/b/157849 fast/frames/crash-during-iframe-load-stop.html [ Pass Timeout ]
webkit.org/b/158085 http/tests/css/shared-stylesheet-mutation.html [ Pass Failure ]
Added: trunk/LayoutTests/http/tests/resources/pass-notify-done.html (0 => 206478)
--- trunk/LayoutTests/http/tests/resources/pass-notify-done.html (rev 0)
+++ trunk/LayoutTests/http/tests/resources/pass-notify-done.html 2016-09-28 00:37:01 UTC (rev 206478)
@@ -0,0 +1,7 @@
+<script>
+function loaded() {
+ if (window.testRunner)
+ setTimeout("testRunner.notifyDone();", 0);
+}
+</script>
+<body _onload_="loaded();">PASS</body>
Modified: trunk/LayoutTests/http/tests/security/anchor-download-block-crossorigin-expected.txt (206477 => 206478)
--- trunk/LayoutTests/http/tests/security/anchor-download-block-crossorigin-expected.txt 2016-09-28 00:31:44 UTC (rev 206477)
+++ trunk/LayoutTests/http/tests/security/anchor-download-block-crossorigin-expected.txt 2016-09-28 00:37:01 UTC (rev 206478)
@@ -1,4 +1 @@
-Downloading URL with suggested filename ""
-Tests that a suggested filename on a download attribute is ignored if the link is cross origin.
-
-The suggested filename at the top should be empty.
+PASS
Modified: trunk/LayoutTests/http/tests/security/anchor-download-block-crossorigin.html (206477 => 206478)
--- trunk/LayoutTests/http/tests/security/anchor-download-block-crossorigin.html 2016-09-28 00:31:44 UTC (rev 206477)
+++ trunk/LayoutTests/http/tests/security/anchor-download-block-crossorigin.html 2016-09-28 00:37:01 UTC (rev 206478)
@@ -4,15 +4,15 @@
<script src=""
<script>
if (window.testRunner)
- testRunner.waitUntilDownloadFinished();
+ testRunner.waitUntilDone();
</script>
</head>
<body>
<p>
-Tests that a suggested filename on a download attribute is ignored if
-<a id="dl" href="" download="foo.pdf">the link</a> is cross origin.
+Tests that the download attribute is ignored if
+<a id="dl" href="" download="FAIL.pdf">the link</a> is cross origin.
<p>
-The suggested filename at the top should be empty.
+It should navigate instead of downloading the file.
<script>
function click(elmt)
{
Modified: trunk/Source/WebCore/ChangeLog (206477 => 206478)
--- trunk/Source/WebCore/ChangeLog 2016-09-28 00:31:44 UTC (rev 206477)
+++ trunk/Source/WebCore/ChangeLog 2016-09-28 00:37:01 UTC (rev 206478)
@@ -1,3 +1,24 @@
+2016-09-27 Chris Dumez <cdu...@apple.com>
+
+ <a download> does not honor the same-origin requirement
+ https://bugs.webkit.org/show_bug.cgi?id=156100
+
+ Reviewed by Alex Christensen.
+
+ We now completely ignore the "download" attribute on anchors if the
+ href URL is cross-origin. We therefore navigate to the URL instead
+ of forcefully downloading it in this case and leave it up to the server
+ to give us the right headers if it should be downloaded. This is
+ conservative and matches Firefox.
+
+ Chrome and the HTML specification ignore only the suggested filename
+ if the URL is cross-origin but still download the file.
+
+ No new tests, updated existing test.
+
+ * html/HTMLAnchorElement.cpp:
+ (WebCore::HTMLAnchorElement::handleClick):
+
2016-09-27 Alex Christensen <achristen...@webkit.org>
URLParser: Handle windows drive letters after two slashes in relative URLs according to spec
Modified: trunk/Source/WebCore/html/HTMLAnchorElement.cpp (206477 => 206478)
--- trunk/Source/WebCore/html/HTMLAnchorElement.cpp 2016-09-28 00:31:44 UTC (rev 206477)
+++ trunk/Source/WebCore/html/HTMLAnchorElement.cpp 2016-09-28 00:37:01 UTC (rev 206478)
@@ -363,12 +363,15 @@
StringBuilder url;
url.append(stripLeadingAndTrailingHTMLSpaces(attributeWithoutSynchronization(hrefAttr)));
appendServerMapMousePosition(url, event);
- URL kurl = document().completeURL(url.toString());
+ URL completedURL = document().completeURL(url.toString());
auto downloadAttribute = nullAtom;
#if ENABLE(DOWNLOAD_ATTRIBUTE)
if (RuntimeEnabledFeatures::sharedFeatures().downloadAttributeEnabled()) {
- downloadAttribute = attributeWithoutSynchronization(downloadAttr);
+ // Ignore the download attribute completely if the href URL is cross origin.
+ bool isSameOrigin = completedURL.protocolIsData() || document().securityOrigin()->canRequest(completedURL);
+ if (isSameOrigin)
+ downloadAttribute = attributeWithoutSynchronization(downloadAttr);
// If the a element has a download attribute and the algorithm is not triggered by user activation
// then abort these steps.
// https://html.spec.whatwg.org/#the-a-element:triggered-by-user-activation
@@ -377,9 +380,9 @@
}
#endif
- frame->loader().urlSelected(kurl, target(), &event, LockHistory::No, LockBackForwardList::No, hasRel(RelationNoReferrer) ? NeverSendReferrer : MaybeSendReferrer, document().shouldOpenExternalURLsPolicyToPropagate(), downloadAttribute);
+ frame->loader().urlSelected(completedURL, target(), &event, LockHistory::No, LockBackForwardList::No, hasRel(RelationNoReferrer) ? NeverSendReferrer : MaybeSendReferrer, document().shouldOpenExternalURLsPolicyToPropagate(), downloadAttribute);
- sendPings(kurl);
+ sendPings(completedURL);
}
HTMLAnchorElement::EventType HTMLAnchorElement::eventType(Event& event)