Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
annevk opened this issue May 15, 2020 · 10 comments
Open

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

annevk opened this issue May 15, 2020 · 10 comments

Comments

@annevk
Copy link
Member

annevk commented May 15, 2020

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

@jugglinmike
Copy link
Contributor

jugglinmike commented May 15, 2020

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."

@annevk
Copy link
Member Author

annevk commented May 16, 2020

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

@mikewest
Copy link
Member

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?

@annevk
Copy link
Member Author

annevk commented May 18, 2020

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.)

@domenic
Copy link
Member

domenic commented Mar 23, 2022

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

@domfarolino
Copy link
Member

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

@annevk
Copy link
Member Author

annevk commented May 25, 2022

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.)

@domfarolino
Copy link
Member

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.

@zcorpan
Copy link
Member

zcorpan commented May 16, 2024

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.

@eligrey
Copy link

eligrey commented May 21, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

7 participants