html icon indicating copy to clipboard operation
html copied to clipboard

Should downloads be "navigate" or "no-cors"

Open annevk opened this issue 5 years ago • 10 comments

Currently in the standard some downloads are the result of navigation and others are the result of the download attribute, which ostensibly fetches directly, but can also navigate, e.g., if you use <a download=x href=https://www.example.com/>test</a> outside of example.com.

I suspect that due to redirects and such it really should just be an input to the navigate algorithm and therefore the mode ought to be "navigate".

This disconnect has a broader impact now due to the existence of the Sec-Fetch-Mode header, see https://bugzilla.mozilla.org/show_bug.cgi?id=1637747.

(I'm pretty sure this was discussed before, but I cannot find the issue.)

cc @mikewest @ckerschb

annevk avatar May 15 '20 08:05 annevk

Chromium has also implemented this with the request mode "navigate."

https://bugs.chromium.org/p/chromium/issues/detail?id=1082429

This has some implications for CORB, as noted in fetch:

  1. If request’s initiator is "download", then return allowed.

    If we recast downloading as navigation this step can be removed.

The pull request which introduced that note may contain the discussion @annevk's thinking of.

I'm having some trouble understanding the distinction between "mode" and "destination" in this case. That may partly be due to the term "navigation request"--a request whose destination is "document." It seems strange that a request can have a mode of "navigate" but not be considered a "navigation request."

jugglinmike avatar May 15 '20 18:05 jugglinmike

I suspect we'd change destination to "document" as well here, though perhaps adding "download" would make sense (and redefining navigation request appropriately).

annevk avatar May 16 '20 07:05 annevk

Chromium implements both kinds of downloads as navigate. It seems reasonable to me for us to bake that into the spec, especially given the behavior @annevk notes above.

If you'd like to add download as a special kind of navigation type that comes from <a download>, I could live with it, but it's not clear to me what the value would be of doing so?

mikewest avatar May 18 '20 09:05 mikewest

There's mode and there's destination. It sounds like we agree that mode should be "navigate". Should destination be "document" as it is for other navigations? That seems fine to me, but I thought I'd offer a different value. (Thinking about it some more a different value might be tricky though given the cross-origin behavior and redirects and such.)

annevk avatar May 18 '20 10:05 annevk

I wonder if target="" works with download="".

domenic avatar Mar 23 '22 21:03 domenic

Looks like neither the spec nor Chrome consider target in the download flow (here's Chrome's code), which might simplify things.

domfarolino avatar May 24 '22 15:05 domfarolino

That's not entirely true, see #7718. <a href="https://example.com/" download target=_blank>Click me</a> will open a new tab. It might be interesting to test what happens if it were to first navigate same-origin and then redirect. (As opposed to window.open() nothing has to be returned synchronously here so there is a bit of leeway to optimize UX.)

annevk avatar May 25 '22 09:05 annevk

Sorry, I meant the download-only path does not respect target. The fallback-to-normal-navigation-in-a-way-that-goes-against-the-spec path is just a normal navigation, which of course respects target and so on, as if we never had the download attribute at all: https://browsing-context.glitch.me/download.html.

But at least in Chrome, if the download-only path is hit (conditions are here) target plays no role.

domfarolino avatar May 25 '22 13:05 domfarolino

CSP is apparently applied differently between download and not-download in Chromium, see https://bugzilla.mozilla.org/show_bug.cgi?id=1862553

Also while I was investigating this, I found that the initiator value "download" (set here) appears to be dead code in the specs.

zcorpan avatar May 16 '24 11:05 zcorpan

I posit that downloads are inherently a "top-level navigation," and should be treated as such.

eligrey avatar May 21 '24 18:05 eligrey