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

Create a new reserved environment for cross-origin redirects. #3891

Merged
merged 9 commits into from
Oct 8, 2018

Conversation

mfalken
Copy link
Contributor

@mfalken mfalken commented Aug 8, 2018

Previously, a navigation would create a reserved environment once,
and use it for all redirects. This commit changes that so
a new environment is created on a cross-origin redirect.

This also runs CSP for each redirect, which is probably more
correct.

Per w3c/ServiceWorker#1316


/browsing-the-web.html ( diff )
/infrastructure.html ( diff )

@mfalken
Copy link
Contributor Author

mfalken commented Aug 8, 2018

@annevk would you be able to review this?
@mikewest for CSP.

@mfalken
Copy link
Contributor Author

mfalken commented Aug 10, 2018

Hum, there's a problem here. Is the intent of creation URL to be after redirects? The service worker spec seems to be using creation URL as the current URL. Maybe that's mistake of the service worker spec though.

The current PR will update creation URL after cross-origin redirects but not same-origin ones, which would be too inconsistent.

@wanderview @jungkees @jakearchibald what do you think?

@wanderview
Copy link
Member

I think the most sane thing is to set the creation URL at the time the settings object is marked execution ready. That would be after all redirects. (FWIW, this is what I implemented in firefox.)

I think we discussed this a bit in regard to SharedWorker here:

w3c/ServiceWorker#1289

Also a bit in here regarding documents:

w3c/ServiceWorker#1091

I'm not sure, though, if the current spec says anything like that.

@wanderview
Copy link
Member

I think the most sane thing is to set the creation URL at the time the settings object is marked execution ready. That would be after all redirects. (FWIW, this is what I implemented in firefox.)

I guess since we don't expose reserved clients it may not matter if the creation URL is set earlier. Any redirects should be complete before execution ready is set and causes the client to be exposed. Changing the reserved environment on redirect should update the creation URL prior to execution ready IMO.

@mfalken
Copy link
Contributor Author

mfalken commented Aug 13, 2018

@wanderview Thanks, that makes sense. I'll update the creation URL on redirects. I agree it shouldn't matter if we do that right after the redirect on the reserved client, or right before execution ready, since reserved clients aren't exposed. Setting it after redirect seems good to me because it's where most of the reserved client is created, and the SW spec might try to access the creation URL of the reserved client rather than the request URL.

Do you know off-hand if we have WPT for this (Client#url after redirects)?

@mfalken
Copy link
Contributor Author

mfalken commented Aug 13, 2018

Revised. This will need WPT for the service worker spec. I'll work on those soon but would prefer to merge this change in parallel of that if it looks good..

@wanderview
Copy link
Member

Do you know off-hand if we have WPT for this (Client#url after redirects)?

I don't see one. And of course we also don't have a WPT test that showing history.pushState() does not change the client.url either. Both of those tests would be great to clarify behavior here.

@mfalken
Copy link
Contributor Author

mfalken commented Aug 13, 2018

Thanks. Another quick question while you're around: do you recall if Client.url for windows is intended to reflect the final response URL (i.e., including respondWith(fetch(url)) or just the request URL after redirects? I know workers are supposed to reflect the response URL (#3771). There was some talk at w3c/ServiceWorker#1031 too.

Yea.. WPT would be good for all this.

@wanderview
Copy link
Member

Oh, interesting question. Since window navigation is a special case and does not reflect the final URL provided to respondWith(), I think it should also not be reflected in the client.url value.

I think that is what we implemented in firefox. See the navigation check here:

https://searchfox.org/mozilla-central/rev/2466b82b729765fb0a3ab62f812c1a96a7362478/dom/serviceworkers/ServiceWorkerEvents.cpp#713-731

(The comment isn't making sense to me right now, though.)

The client.url is then set to nsIDocument::GetOriginalURI() which is the after-redirect URL of the document:

https://searchfox.org/mozilla-central/rev/2466b82b729765fb0a3ab62f812c1a96a7362478/dom/clients/manager/ClientSource.cpp#266

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Aug 22, 2018
In preparation for extending or modifying the test to test Client.url
and resultingClientId for whatwg/html#3891.

Bug: 876223
Change-Id: I50e8b8c21c5f8639a24a9c2ec00df3ccafdc8ac8
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Aug 24, 2018
In preparation for extending or modifying the test to test Client.url
and resultingClientId for whatwg/html#3891.

Bug: 876223
Change-Id: I50e8b8c21c5f8639a24a9c2ec00df3ccafdc8ac8
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Aug 24, 2018
In preparation for extending or modifying the test to test Client.url
and resultingClientId for whatwg/html#3891.

Bug: 876223
Change-Id: I50e8b8c21c5f8639a24a9c2ec00df3ccafdc8ac8
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Aug 24, 2018
In preparation for extending or modifying the test to test Client.url
and resultingClientId for whatwg/html#3891.

Bug: 876223
Change-Id: I50e8b8c21c5f8639a24a9c2ec00df3ccafdc8ac8
Reviewed-on: https://chromium-review.googlesource.com/1184656
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Reviewed-by: Makoto Shimazu <shimazu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585738}
aarongable pushed a commit to chromium/chromium that referenced this pull request Aug 24, 2018
In preparation for extending or modifying the test to test Client.url
and resultingClientId for whatwg/html#3891.

Bug: 876223
Change-Id: I50e8b8c21c5f8639a24a9c2ec00df3ccafdc8ac8
Reviewed-on: https://chromium-review.googlesource.com/1184656
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Reviewed-by: Makoto Shimazu <shimazu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585738}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Aug 24, 2018
In preparation for extending or modifying the test to test Client.url
and resultingClientId for whatwg/html#3891.

Bug: 876223
Change-Id: I50e8b8c21c5f8639a24a9c2ec00df3ccafdc8ac8
Reviewed-on: https://chromium-review.googlesource.com/1184656
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Reviewed-by: Makoto Shimazu <shimazu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585738}
zcorpan pushed a commit to web-platform-tests/wpt that referenced this pull request Aug 27, 2018
In preparation for extending or modifying the test to test Client.url
and resultingClientId for whatwg/html#3891.

Bug: 876223
Change-Id: I50e8b8c21c5f8639a24a9c2ec00df3ccafdc8ac8
Reviewed-on: https://chromium-review.googlesource.com/1184656
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Reviewed-by: Makoto Shimazu <shimazu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585738}
@domenic domenic requested a review from annevk August 28, 2018 03:29
Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unclear why we need request cloning here and manipulation of request's URL list. It seems too much of Fetch is creeping into the navigate algorithm.

source Outdated
<span data-x="concept-environment-creation-url">creation URL</span> matches a service worker
registration. <ref spec="SW"></p>
</li>
<li><p>Repeat the following steps until <var>done</var> is true:</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While done is false*

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, since this has more than one nested element the <p> needs to be newlined

source Outdated
@@ -2830,10 +2830,13 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
data-x-href="https://fetch.spec.whatwg.org/#concept-request">request</dfn> and its associated:
<ul class="brief">
<li><dfn data-x="concept-request-url" data-x-href="https://fetch.spec.whatwg.org/#concept-request-url">url</dfn></li>
<li><dfn data-x="concept-request-url-list" data-x-href="https://fetch.spec.whatwg.org/#concept-request-url-list">url list</dfn></li>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

URL list*

<li><dfn data-x="concept-request-method" data-x-href="https://fetch.spec.whatwg.org/#concept-request-method">method</dfn></li>
<li><dfn data-x="concept-request-header-list" data-x-href="https://fetch.spec.whatwg.org/#concept-request-header-list">header list</dfn></li>
<li><dfn data-x="concept-request-body" data-x-href="https://fetch.spec.whatwg.org/#concept-request-body">body</dfn></li>
<li><dfn data-x="concept-request-client" data-x-href="https://fetch.spec.whatwg.org/#concept-request-client">client</dfn></li>
<li><dfn data-x="concept-request-clone" data-x-href="https://fetch.spec.whatwg.org/#concept-request-clone">clone</dfn></li>
<li><dfn data-x="concept-request-current-url" data-x-href="https://fetch.spec.whatwg.org/#concept-request-current-url">current url</dfn></li>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

current URL

source Outdated
client</span> to <var>reservedEnvironment</var>.</p></li>
<ol>
<li><p>Let <var>newRequest</var> be a <span data-x="concept-request-clone">clone</span> of
<var>request</var>.</li>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closing </p>

source Outdated
<ref spec="CSP"></p>
<li><p>If <var>response</var> is not null, append <var>response</var>'s <span
data-x="concept-response-location-url">location URL</span> to <var>newRequest</var>'s
<span data-x="concept-request-url-list">url list.</span></p></li>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dot outside the span element.

source Outdated

<p>Otherwise:</p>
<li>
<p>If <var>reservedEnvironment</var> is not null, and <var>newRequest's</var>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

's outside the var element

source Outdated

<li><p>If <var>reservedEnvironment</var> is null, let <var>reservedEnvironment</var> be a new
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/let/then set/
s/be/to/

source Outdated

<li><p>If <var>reservedEnvironment</var> is null, let <var>reservedEnvironment</var> be a new
<span>environment</span>, and set its <span data-x="concept-environment-id">id</span> to a new
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"a new environment whose id is ... and target browsing context is ..."

source Outdated
<var>browsingContext</var>, then set <var>response</var> to a network error, and set
<var>done</var> to true. <ref spec="CSP"></p></li>

<li><p>Otherwise:</p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newline <p>

source Outdated
<li><p>If the <span>Should navigation request of type from source in target be blocked by Content
Security Policy?</span> algorithm returns "<code data-x="">Blocked</code>" when executed upon
<var>newRequest</var>, <var>navigationType</var>, <var>sourceBrowsingContext</var>, and
<var>browsingContext</var>, then set <var>response</var> to a network error, and set
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

link network error

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for comma before "and set" as there's only two actions.

@annevk
Copy link
Member

annevk commented Aug 28, 2018

(Apologies for the delay here by the way. I overlooked this somehow.)

moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Aug 29, 2018
… navigation-redirect.https.html., a=testonly

Automatic update from web-platform-testsWPT: service worker: Refactor and format navigation-redirect.https.html.

In preparation for extending or modifying the test to test Client.url
and resultingClientId for whatwg/html#3891.

Bug: 876223
Change-Id: I50e8b8c21c5f8639a24a9c2ec00df3ccafdc8ac8
Reviewed-on: https://chromium-review.googlesource.com/1184656
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Reviewed-by: Makoto Shimazu <shimazu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585738}

--

wpt-commits: 1bc6d9975ef38c3ade2986dff737b4421c6352df
wpt-pr: 12610
jankeromnes pushed a commit to jankeromnes/gecko that referenced this pull request Aug 29, 2018
… navigation-redirect.https.html., a=testonly

Automatic update from web-platform-testsWPT: service worker: Refactor and format navigation-redirect.https.html.

In preparation for extending or modifying the test to test Client.url
and resultingClientId for whatwg/html#3891.

Bug: 876223
Change-Id: I50e8b8c21c5f8639a24a9c2ec00df3ccafdc8ac8
Reviewed-on: https://chromium-review.googlesource.com/1184656
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Reviewed-by: Makoto Shimazu <shimazu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585738}

--

wpt-commits: 1bc6d9975ef38c3ade2986dff737b4421c6352df
wpt-pr: 12610
@mfalken
Copy link
Contributor Author

mfalken commented Aug 31, 2018

Thank you for the review!

Sorry I'm not good at git... looks like I messed up this PR trying to sync with upstream changes.

@mfalken
Copy link
Contributor Author

mfalken commented Aug 31, 2018

I'm unclear why we need request cloning here and manipulation of request's URL list. It seems too much of Fetch is creeping into the navigate algorithm.

Hum, I think I needed this for the "Should navigation request of type from source in target be blocked by Content Security Policy?" step. I thought it should use request with the new URL added to it. But we can't modify request directly here since the Fetch spec also modifies it in HTTP-redirect fetch.

However, it looks like https://w3c.github.io/webappsec-csp/#should-block-navigation-request uses "request's URL". There are two problems here:

  • URL links to the "response URL" concept in the Fetch spec, which looks wrong
  • It probably means to link to "request URL" which seems to be the first URL of the redirect chain, in which case appending the request to the list won't help.

I guess I can keep CSP as is for this change (keep passing request), and can probably forgo the cloning.

@mfalken
Copy link
Contributor Author

mfalken commented Aug 31, 2018

@annevk thanks, I addressed your feedback.

(I think I was able to recover the PR by using git push -f to cancel the previous bad push)

@mfalken
Copy link
Contributor Author

mfalken commented Sep 5, 2018

Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks a lot better, thanks. Did you file issues against CSP for the issues you found?

source Show resolved Hide resolved
source Show resolved Hide resolved
source Show resolved Hide resolved
source Show resolved Hide resolved
source Show resolved Hide resolved
source Show resolved Hide resolved
@mfalken
Copy link
Contributor Author

mfalken commented Sep 6, 2018

Thanks! I will be away for some time but plan to get back to this ASAP.

Previously, a navigation would create a reserved environment once,
and use it for all redirects. This commit changes that so
a new environment is created on a cross-origin redirect.

This also runs CSP for each redirect, which is probably more
correct.

Per w3c/ServiceWorker#1316
@mfalken
Copy link
Contributor Author

mfalken commented Sep 28, 2018

Thanks! I'm preparing a patch in response to your comments.

Did you file issues against CSP for the issues you found?

Filed w3c/webappsec-csp#343

@mfalken
Copy link
Contributor Author

mfalken commented Sep 28, 2018

@annevk I believe I addressed your comments. Please take another look.

Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good, modulo nits. You should also ensure there are two newlines between any </p> and <ol>.

I'd love it if @wanderview could have a look as well, given he's somewhat familiar with all this and might be able to spot more.

source Show resolved Hide resolved
source Show resolved Hide resolved
@mfalken
Copy link
Contributor Author

mfalken commented Oct 3, 2018

Thanks @annevk! Updated. @wanderview did you want to look as well?

@wanderview
Copy link
Member

LGTM

Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Tests already landed? And presumably there's cross-browser support since this is a bug fix.

@mfalken
Copy link
Contributor Author

mfalken commented Oct 5, 2018

Thanks! Yes, tests landed in web-platform-tests/wpt@2df7f9f#diff-f23ebe2bdee04a9c0b8ab094be59f318

And yes, I think this was the consensus from previous F2Fs and in the latest issue:
w3c/ServiceWorker#1031 (comment)
w3c/ServiceWorker#1316

@annevk
Copy link
Member

annevk commented Oct 5, 2018

Great, are there implementation bugs? If those are filed this is ready to land.

@mfalken
Copy link
Contributor Author

mfalken commented Oct 5, 2018

There are bugs against resultingClientId (which the WPT depends on) at:

@annevk annevk merged commit 45ddbd2 into whatwg:master Oct 8, 2018
@annevk
Copy link
Member

annevk commented Oct 8, 2018

Thanks!

gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this pull request Oct 3, 2019
… navigation-redirect.https.html., a=testonly

Automatic update from web-platform-testsWPT: service worker: Refactor and format navigation-redirect.https.html.

In preparation for extending or modifying the test to test Client.url
and resultingClientId for whatwg/html#3891.

Bug: 876223
Change-Id: I50e8b8c21c5f8639a24a9c2ec00df3ccafdc8ac8
Reviewed-on: https://chromium-review.googlesource.com/1184656
Commit-Queue: Matt Falkenhagen <falkenchromium.org>
Reviewed-by: Kinuko Yasuda <kinukochromium.org>
Reviewed-by: Makoto Shimazu <shimazuchromium.org>
Cr-Commit-Position: refs/heads/master{#585738}

--

wpt-commits: 1bc6d9975ef38c3ade2986dff737b4421c6352df
wpt-pr: 12610

UltraBlame original commit: 3da52ed85a2cb6a6c6b61cb230bd008bb397e629
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request Oct 3, 2019
… navigation-redirect.https.html., a=testonly

Automatic update from web-platform-testsWPT: service worker: Refactor and format navigation-redirect.https.html.

In preparation for extending or modifying the test to test Client.url
and resultingClientId for whatwg/html#3891.

Bug: 876223
Change-Id: I50e8b8c21c5f8639a24a9c2ec00df3ccafdc8ac8
Reviewed-on: https://chromium-review.googlesource.com/1184656
Commit-Queue: Matt Falkenhagen <falkenchromium.org>
Reviewed-by: Kinuko Yasuda <kinukochromium.org>
Reviewed-by: Makoto Shimazu <shimazuchromium.org>
Cr-Commit-Position: refs/heads/master{#585738}

--

wpt-commits: 1bc6d9975ef38c3ade2986dff737b4421c6352df
wpt-pr: 12610

UltraBlame original commit: 3da52ed85a2cb6a6c6b61cb230bd008bb397e629
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this pull request Oct 3, 2019
… navigation-redirect.https.html., a=testonly

Automatic update from web-platform-testsWPT: service worker: Refactor and format navigation-redirect.https.html.

In preparation for extending or modifying the test to test Client.url
and resultingClientId for whatwg/html#3891.

Bug: 876223
Change-Id: I50e8b8c21c5f8639a24a9c2ec00df3ccafdc8ac8
Reviewed-on: https://chromium-review.googlesource.com/1184656
Commit-Queue: Matt Falkenhagen <falkenchromium.org>
Reviewed-by: Kinuko Yasuda <kinukochromium.org>
Reviewed-by: Makoto Shimazu <shimazuchromium.org>
Cr-Commit-Position: refs/heads/master{#585738}

--

wpt-commits: 1bc6d9975ef38c3ade2986dff737b4421c6352df
wpt-pr: 12610

UltraBlame original commit: 3da52ed85a2cb6a6c6b61cb230bd008bb397e629
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants