-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Clean up <link>'s "obtain a resource" Fetch and Resource Hints integration #1142
Comments
I guess the 404 requirement might need to be turned into some "ok status" check on the return value? (Seems a bit dubious for "no-cors", though I guess the platform has several of those. On the other hand, @jakearchibald thinks this is a problem with AppCache I believe... Or maybe that's because AppCache has specific behavior for certain 4xx status codes.) |
Here's where we discussed this for service worker w3c/ServiceWorker#258 If we decide it's ok to expose this, I'd be happy to make it ok in service worker land & fetch too. However, if a site 403s vs 200s depending on login state, it feels like something we wouldn't want to openly reveal. |
So... At least |
Media elements, The only one that can be used to detect cross-origin 404s for any resource is http://output.jsbin.com/heyiqa/quiet Chrome fires a "load" for 404s. Firefox & Safari do not fire a "load" event for 404s, but they don't fire an "error" event either. |
Ah I see, so the attack vector is specific 4xx status codes, not treating 2xx specially. Maybe that argues for allowing "ok" on opaque responses coupled with Cache API support? Going off a bit into the weeds here... |
I'd be delighted with that, but I think it gives more visibility than we have today, so I'd like a second opinion from The Security Avengers. For example, I'm not sure I can determine |
Yeah, maybe it does, depends on the precise processing model of the various elements and that's likely not generic enough. |
This is a bug in Firefox; it pretty much never fires "error" on |
I guess the current Firefox behavior is to fire "load" on success, nothing on failure, so you can just wait a bit and then decide the thing failed. Firing "error" won't make this any worse, at least.... |
This alerts 2 in browsers. |
I know @mikewest changed Chrome to fail |
We should think about what |
So yeah, it seems that |
Huh, do browser fire the load event even if the script doesn't parse? |
Yeah, though |
So, right now the Fetch integration happens through https://html.spec.whatwg.org/multipage/semantics.html#concept-link-obtain, which is right above the quoted text. But that also seems like it should be superceded, at least in part, by #968 (CSSOM's "fetch a stylesheet" algorithm). I'm not sure what to do about CSSOM integration, but I think the correct fix for this bug and for #1148 is the following:
So currently I think we are blocked on, as @jakearchibald says, the Security Avengers telling us about whether error events are a good idea or not. |
If someone has bandwidth, we could figure out what happens for |
In Firefox,
There are also some complications in terms of what happens with |
Note that I'm rather keenly interested in knowing exactly what Chrome does here for |
@mikewest Do you know who would know about the Chrome behavior details here? |
A comment on the |
@bzbarsky: I'd bother @igrigorik or @yoavweiss about anything and everything For |
@mikewest Yeah, I gave up on ever hearing back from you guys and we just went ahead and implemented something. To whit:
|
To be clear, And how is the |
This seems significantly better nowadays. Here is my summary of what remains. We may want to close this issue and split it into other more focused issues.
/cc @domfarolino |
I now think I dropped the ball on preload, since it fulfills all of the conditions I listed in #6122 and the spec expects the In any case, if the |
https://html.spec.whatwg.org/multipage/links.html#link-type-preload However, https://wpt.fyi/results/preload/onerror-event.html expects Perhaps this WPT/browsers behavior is reasonable for scripts (where main requests to the same URL would also fire error events due to HTTP Status 404) and others. But for
|
Hmm, if cc @noamr |
Yes, I believe I covered this in WPT. Preloads don't handle 404 especially |
Yeah the preload spec doesn't handle 404 especially, but main requests do handle 404 differently depending on the types:
More generally, the question might be: in different words, what would be the condition of the error event of
Note: while Chromium fires |
2 or exactly matching the main request (though would this make the |
(2) makes the most sense to me. I don't think preloads should deal with image decoding errors... I'll investigate if this is WPTed/interoperable. |
Thanks for your inputs! As for
WPT: web-platform-tests/wpt#33382 Chromium implementation is easy and probably we need this change in order to fix https://bugs.chromium.org/p/chromium/issues/detail?id=1305317. As the current behavior for the cases to be fixed is already not interoperable, I hope the compatibility risk is not high. As for other 404 cases (i.e. changing from (3) to (2)), the complexity of the Chromium implementation change (if needed) is medium. Not sure about the compatibility risk though, because I haven't investigated the current behavior. As for non-404 cases where (4)/(5) is different from (2)/(3) (e.g. image decode errors), I expect the Chromium implementation change would be much larger. |
I'm OK with (2) to maximize interoperability + privacy. |
Updated WPT web-platform-tests/wpt#33382 HTTP 404:
CORS Failures
Image decode error:
Stylesheets with non-text/css MIME Type (without nosniff):
Classic scripts with non-JavaScript MIME type (without nosniff, listed in https://fetch.spec.whatwg.org/#should-response-to-request-be-blocked-due-to-mime-type?):
(let me know if I'm missing something, e.g. as for understanding the specs)
|
While people here basically agreed on (2) in #1142 (comment), I'm leaning toward leaving this issue pending for now, because I'm not so sure about the risks and implementability: I feel some of the behavior changes in #1142 (comment) are not so small, particularly firing load events instead of error events on Firefox/Safari/Chrome for
and I don't have sufficient bandwidth or motivating dependencies right now for e.g. further investigating the uses and impacts of these events in the wild. Also changing the events for broken images might have nontrivial implementation work in Chromium. On the other hand, I'd like to land the spec PR #7799 (perhaps with a note that the issue is still open) and its WPT (perhaps as tentative), to anyway monitor the behavior, as the current spec is anyway further deviating from the current browsers' behavior. Does this plan look good? |
A part of #1142. Although no browsers match this exactly, and implementers aren't sure this will be implementable, this is at least closer to reality than the previous spec, and reflects the direction everyone wants to go.
Previously, when XHR/fetch API reuses a <link rel=preload as=fetch> response with HTTP 4xx, XHR onabort was fired and fetch API's text() was stalled (never resolved nor rejected), due to loading cancellation, while XHR/fetch API should be successful because HTTP 4xx isn't considered as a network error in the spec. This CL fixes this by not considering HTTP 4xx as an error. As a side effect, this CL fires load events instead of error events for <link rel=preload as=fetch> + HTTP 4xx. While the desired behavior about the events on `<link rel=preload as=fetch>` are still under discussion at whatwg/html#1142, changing the event on Chromium is probably fine, because Firefox/Safari fire different events (load/error, respectively) for HTTP 4xx. Original attempt: https://chromium-review.googlesource.com/c/chromium/src/+/3540965 Bug: 1305317, 1318618 Change-Id: Ic8ec587599f4db28837ed3c1b19b2a5a58e1a4c4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3585999 Reviewed-by: Mason Freed <[email protected]> Commit-Queue: Hiroshige Hayashizaki <[email protected]> Cr-Commit-Position: refs/heads/main@{#996524}
A part of whatwg#1142. Although no browsers match this exactly, and implementers aren't sure this will be implementable, this is at least closer to reality than the previous spec, and reflects the direction everyone wants to go.
Previously, when XHR/fetch API reuses a <link rel=preload as=fetch> response with HTTP 4xx, XHR onabort was fired and fetch API's text() was stalled (never resolved nor rejected), due to loading cancellation, while XHR/fetch API should be successful because HTTP 4xx isn't considered as a network error in the spec. This CL fixes this by not considering HTTP 4xx as an error. As a side effect, this CL fires load events instead of error events for <link rel=preload as=fetch> + HTTP 4xx. While the desired behavior about the events on `<link rel=preload as=fetch>` are still under discussion at whatwg/html#1142, changing the event on Chromium is probably fine, because Firefox/Safari fire different events (load/error, respectively) for HTTP 4xx. Original attempt: https://chromium-review.googlesource.com/c/chromium/src/+/3540965 Bug: 1305317, 1318618 Change-Id: Ic8ec587599f4db28837ed3c1b19b2a5a58e1a4c4 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3585999 Reviewed-by: Mason Freed <[email protected]> Commit-Queue: Hiroshige Hayashizaki <[email protected]> Cr-Commit-Position: refs/heads/main@{#996524} NOKEYCHECK=True GitOrigin-RevId: 2feeb37f75b06beea1bafa843a11f9199ffb3739
According to whatwg/html#1142 we expect `onerror` event of `<link rel=preload>` to be fired only on network errors and not on `404`.
According to whatwg/html#1142 we expect `onerror` event of `<link rel=preload>` to be fired only on network errors and not on `404`.
…on network error, a=testonly Automatic update from web-platform-tests Make preload links fire `onerror` event on network error According to whatwg/html#1142 we expect `onerror` event of `<link rel=preload>` to be fired only on network errors and not on `404`. -- wpt-commits: 408e27341a3bdbbdaa155bf21f62e9d3a8e26920 wpt-pr: 39727
…on network error, a=testonly Automatic update from web-platform-tests Make preload links fire `onerror` event on network error According to whatwg/html#1142 we expect `onerror` event of `<link rel=preload>` to be fired only on network errors and not on `404`. -- wpt-commits: 408e27341a3bdbbdaa155bf21f62e9d3a8e26920 wpt-pr: 39727
This no longer seems to have a place now we use Fetch.
The text was updated successfully, but these errors were encountered: