-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Test for opaque redirect handling #10449
Conversation
@jakearchibald @wanderview I'd appreciate your help with this. This is the first service worker code/"test" I've written... I've run it in Firefox and it doesn't do what I discussed in whatwg/fetch#633 as the problematic scenario. It resolves the I don't think you can violate the same-origin policy with this and we only ever handle these type of responses for navigation requests, which will be same-origin with the service worker, but it still seems a little sketchy and might allow a clever XSS to exfiltrate redirect data? |
@annevk You probably need to wait for the service worker to activate with BTW, now that we can use async functions some of this can be cleaner to write. |
+1 to async functions & https://github.com/w3c/web-platform-tests/pull/10348/files#diff-2098c79116c31c91424e3965506554a3R41 - here's the pattern I use. |
I also tend to put files that aren't defining tests into a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM aside from the nits mentions, and wait_for_state
.
e.respondWith(new Promise(async resolve => { | ||
evilGlobalState = await fetch(e.request); | ||
resolve(new Response("stage 1 completed\n")); | ||
})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the above 4 lines could be:
evilGlobalState = fetch(e.request);
e.respondWith(new Response("stage 1 completed\n"));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't that increase the chance evilGlobalState is null when the second fetch comes in?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but if that's your intent then use waitUntil
event.waitUntil(new Promise(r => self.globalStateCollected = r));
And call globalStateCollected()
once evilGlobalState
is no longer needed.
That's true, but if you use a unique scope it doesn't matter in practice. (Async cleanup would be great, though.) |
Should be (mostly) good now! Thanks again for the help. As I noted on IRC, Safari passes this. I'm not sure how to run this in Edge via BrowserStack yet. |
I think the service worker should go in resources too right? |
Other than the above, LGTM. |
8e87d5c
to
4fcb0f3
Compare
I fixed that issue. What remains is that we need to decide how we want to handle redirects more generally as per the linked Fetch issue and then also add tests for those other scenarios. |
As per whatwg/fetch#633 (comment) except using global state instead of the cache API. (Improvements welcome!)
da25c99
to
1142b6c
Compare
Hmm, should |
As per whatwg/fetch#633 (comment) except using global state instead of the cache API. (Improvements welcome!)