-
Notifications
You must be signed in to change notification settings - Fork 72
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
Multiple fallback URLs and interaction with CORS #76
Comments
Not treating CORS failures as fallbacks seems an adequate solution this. Or are there other cases or factors that might still come into play? |
I think you're right that if CORS isn't considered when deciding to go to the next fallback option (i.e. making it so that you try the next fallback if and only if its an actual network failure) then that handles the uniqueness problem. Hopefully I'm remembering this correctly, but I think one specific concern that @hiroshige-g had about this was that it might let you distinguish between when the resource failed specifically because of CORS. If this provides any way for users to resolve If you had this import map: {
"imports": {
"name": ["http://vulnerable-host/", "http://cors-leak-sentinel.com/"],
}
} ... then you could determine whether or not
Basically, is it dangerous to allow users to know whether or not CORS is the reason they can't access something? If so, does that mean that import maps has a mutually-exclusive choice between allowing multiple URLs in the fallback list and allowing the user to know the resolved network URL of an |
Option 0. We fallback if
If we don't treat CORS failures as fallbacks for Option 1. We fallback if In this case there are no information leak, as no-cors Fetch API request is already exposed to JavaScript.
Therefore:
Option 2. We send a (cors) main request to In this case we don't need the additional request. However,
|
In the previous offline discussion with @bicknellr, I was thinking of Option 0/2 but missed Option 1. |
Even without |
As far as I'm aware, CORS errors are already detectable because they return a status code 0 and empty body right? That is, the security risk mitigation of CORS is spilling any header or response information itself from the origin, not in the information of whether or not there was a CORS failure. You can know you've been blocked by CORS through the status code 0, but you can't get any more specific information than that. Please correct me if I'm wrong here though.
@hiroshige-g could you clarify this inconsistency further? If the import map resolves to Also, when you mention these fetch requests in the options, are you considering these requests to be like "preflight" requests used only for resolution? Am I right in thinking that all options you describe effectively make this request to resolve the import map before passing the resolved URL down further? If that is the case I'd be somewhat concerned about the performance of this approach in incurring latency for every package fallback resolution. I tend to think aiming for a lower-level solution to this closer to the connection level when handling lots of fallbacks would be useful to avoid this. |
I haven't read this large thread all the way through yet, but in case it hasn't been mentioned, I was thinking one solution in this problem space is to make all import: URL-initiated fetches use CORS. Apologies if that's already been discussed; I will try to read more later. |
Essentially any difference (not only CORS) in <img id="A" src="import:some-image" crossorigin="anonymous">
<img id="B" src="import:some-image" crossorigin="use-credentials"> |
There are no ways to distinguish whether the status code 0 (in XHRs) is caused by CORS errors or by other kinds of network failures from a single CORS request/response.
I felt this is inconsistent (import map resolution succeeded and resolving to
Yes for Option 1. For Options 0 and 2, we do only a single import-map-resolution==main request if it succeeds.
Agree.
Is this something like the following? Option 3. We connect to Pros:
Cons:
|
OK, I've read through this thread now. Thanks very much for folks thinking through these details. Thanks for explaining. I think there are broadly two solutions here. I am not sure how they map to your options 0-3. Be consistent with
|
@hiroshige-g found these:
The
crossorigin
attribute allows the user to control how a request is made and how it is interpreted when received. When paired with multiple URL fallbacks, if CORS failures are considered a condition for falling back to the next URL, then it is not true that a singleimport:
URL - even within the same scope - maps to a single, unique network URL.For example, given this HTML:
If the import map controlling the scope that these
<img>
s both use for mapping thesrc
attribute specifies thatimport:some-image
should map to these network URLs: [https://example.com/image-a.jpg
,https://example.com/image-b.jpg
], andhttps://example.com/image-a.jpg
does not have a compatible value forAccess-Control-Allow-Origin
, then#A
would result inimport:some-image
mapping tohttps://example.com/image-a.jpg
and#B
would result inimport:some-image
mapping tohttps://example.com/image-b.jpg
.Multiple fallback URLs and CORS also means it's not possible to implement an "
import.resolve
" API that allows the user to mapimport:
URLs to network URLs themselves because the CORS issue described above means that the context in which a particular URL would be used determines whether or not fallback would happen.The text was updated successfully, but these errors were encountered: