Skip to content

Response body stream from SW has wrong realm #731

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

Open
jyasskin opened this issue May 22, 2018 · 4 comments
Open

Response body stream from SW has wrong realm #731

jyasskin opened this issue May 22, 2018 · 4 comments

Comments

@jyasskin
Copy link
Member

jyasskin commented May 22, 2018

If I'm tracing this correctly, a fetch() from a Window that's handled by a Service Worker returns a Response object in the Window's realm associated with the response struct created by the Service Worker and returned via https://fetch.spec.whatwg.org/#http-fetch. That response struct contains a body with a stream containing a ReadableStream object created in https://w3c.github.io/ServiceWorker/#fetch-event-respondwith that's associated with the Service Worker's realm.

https://w3c.github.io/ServiceWorker/#fetch-event-respondwith copies the stream, and w3c/ServiceWorker#934 says it's trying to do this exactly to get the realms right, but it uses targetRealm defined as "relevant Realm of the context object" of the FetchEvent, which is just the Service Worker's realm again, not the fetch() call's realm. I believe this copy needs to be done inside Fetch in order to have the right realm available, not inside the Service Worker spec. (@yutakahirano)

This might be a sign that it's a mistake to have the body struct contain a Javascript object, but streams don't provide a non-Javascript abstraction for the body to contain instead. (@domenic)

@annevk
Copy link
Member

annevk commented May 23, 2018

Yeah, this (and #730) strongly argue for an abstract stream being available.

@annevk
Copy link
Member

annevk commented Feb 2, 2021

@domenic @jakearchibald @ricea thoughts on how to handle this?

@ricea
Copy link
Collaborator

ricea commented Feb 4, 2021

In this specific case I think it would make sense to say the stream is cloned and then the clone is transferred to the appropriate realm.

This doesn't solve the general problem of being able to talk about streams that aren't tied to a specific realm.

@annevk
Copy link
Member

annevk commented Feb 4, 2021

@yutakahirano this relates to that other issue you are working on with regards to how Fetch and Service Workers should integrate when it comes to streams.

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

No branches or pull requests

3 participants