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

referer / referrer during reloads & history entry repopulations #6813

Closed
jakearchibald opened this issue Jun 29, 2021 · 8 comments · Fixed by #6315
Closed

referer / referrer during reloads & history entry repopulations #6813

jakearchibald opened this issue Jun 29, 2021 · 8 comments · Fixed by #6315
Labels
interop Implementations are not interoperable with each other topic: history

Comments

@jakearchibald
Copy link
Contributor

jakearchibald commented Jun 29, 2021

History entry repopulations: When you traverse to a history entry that doesn't have a document, so it needs refetching.

I've been testing using https://redirect-session-history.glitch.me, and it seems like, when reloading a page or traversing back to a page, browsers will send the same referer that was originally used for the first fetch of the page.

That includes cases like:

  1. Page //origin-1/a
  2. Navigate to page //origin-1/b (so referrer is //origin-1/a)
  3. Reload, which redirects to //origin-1/c

//origin-1/c will have a referrer of //origin-1/a.

One minor browser difference:

  1. Page //origin-1/a
  2. Navigate to page //origin-1/b (so referrer is //origin-1/a)
  3. Reload, which redirects to //totally-different-origin/foo, which redirects back to //origin-1/c

In this case Chrome and Firefox simplify the referrer to //origin-1/ (with the full origin of course), whereas Safari uses the full referrer //origin-1/a.

My plan is to spec the Chrome & Firefox behaviour by storing the referrer along with the "document state". The document state is the state needed to recreate a document, and is shared between multiple session history entries (entries that will share a document).

@jakearchibald
Copy link
Contributor Author

jakearchibald commented Jun 29, 2021

Btw, let me know if this stuff is spec'd and I just can't find it. I followed the spec for reload() and it seems like the referrer just ends up as "client", meaning the referrer would be itself, which isn't what browsers do.

@domenic
Copy link
Member

domenic commented Jun 29, 2021

I wonder how referrer policy plays into this... usually its drawn from the fetch client. So imagine something like

  1. //origin-1/a with referrer policy "unsafe-url"
  2. //origin-1/b
  3. //origin-1/c with referrer policy "no-referrer"

When navigating from 1 -> 2 the referrer would be //origin-1/a, the full URL. Then we navigate to 3. What if we click the back button then (with no bfcache)? Should the referrer be missing, based on 3's referrer policy? Or should it be //origin-1/a, the original referrer? If the latter, how do we thread that through specs?

@domenic
Copy link
Member

domenic commented Jun 29, 2021

If the latter, how do we thread that through specs?

I guess we could just set the referrer explicitly and then set the referrer policy to the empty string. Not so bad.

@jakearchibald
Copy link
Contributor Author

Yeah, right now I'm allowing the referrer to be a URL or "no-referrer", which are used by fetch.

@jakearchibald
Copy link
Contributor Author

Referrer policy is stored in the history entry too. Test:

  1. Page //origin-1/a.
  2. Navigate to page //origin-1/b using a link with referrerpolicy="same-origin" (so referrer is //origin-1/a).
  3. Reload, which redirects to //totally-different-origin/foo.

Firefox and Chrome will omit Referer. Safari will send the full referrer //origin-1/a.

I'm going continue speccing the Chrome & Firefox behaviour.

@annevk
Copy link
Member

annevk commented Jul 21, 2021

See also w3c/webappsec-fetch-metadata#71.

@domenic
Copy link
Member

domenic commented Aug 6, 2021

It turns out Chromium and WebKit distinguish between user-triggered reloads and other reloads. Test case:

  • Go to https://example.com/
  • Click the "more information" link taking you to https://www.iana.org/domains/reserved
  • Open your console and type document.referrer. You get https://example.com/
  • Press the reload button on your browser
  • Open your console and type document.referrer. You get https://example.com/
  • In the same console, type location.reload().
  • Open your console and type document.referrer. You get:
    • https://example.com/ in Firefox
    • https://www.iana.org/domains/reserved in Chromium, due to this code
    • https://www.iana.org/domains/reserved in WebKit

@domenic domenic added the interop Implementations are not interoperable with each other label Aug 6, 2021
@domenic
Copy link
Member

domenic commented Oct 10, 2022

@domfarolino is working on some tests for this in web-platform-tests/wpt#36352 . However it's for the repopulation case, not the reload case.

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue May 6, 2023
This CL is a follow-up to https://crrev.com/c/3936785 and
whatwg/html#6813 (comment). It
adds a test asserting the document state preservation as described more
below, in the `location.reload()` case, alongside a very similar test
that asserts the same for the document repopulation case.

The HTML Standard specifies the behavior of `location.reload()` to
preserve the existing history entry's document state's initiator origin
and referrer, as described in:
https://html.spec.whatwg.org/multipage/browsing-the-web.html#apply-the-history-step:~:text=If%20targetEntry%27s%20document%20is%20null%2C%20or%20targetEntry%27s%20document%20state%27s%20reload%20pending%20is%20true%2C%20then.

This means that when a page is navigated to from a cross-origin
predecessor, and then `location.reload()`s itself, `Sec-Fetch-Site`
should be `cross-site` and the `Referer` header should remain the same
as the original navigation.

Chromium currently fails this test, per
whatwg/html#6813 (comment) and
the code pointer described by that comment.

[email protected]

Bug: N/A
Change-Id: I868ac9fad7e63df251d6c4b0d0ac8b099b81d25b
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue May 17, 2023
This CL is a follow-up to https://crrev.com/c/3936785 and
whatwg/html#6813 (comment). It
adds a test asserting the document state preservation as described more
below, in the `location.reload()` case, alongside a very similar test
that asserts the same for the document repopulation case.

The HTML Standard specifies the behavior of `location.reload()` to
preserve the existing history entry's document state's initiator origin
and referrer, as described in:
https://html.spec.whatwg.org/multipage/browsing-the-web.html#apply-the-history-step:~:text=If%20targetEntry%27s%20document%20is%20null%2C%20or%20targetEntry%27s%20document%20state%27s%20reload%20pending%20is%20true%2C%20then.

This means that when a page is navigated to from a cross-origin
predecessor, and then `location.reload()`s itself, `Sec-Fetch-Site`
should be `cross-site` and the `Referer` header should remain the same
as the original navigation.

Chromium currently fails this test, per
whatwg/html#6813 (comment) and
the code pointer described by that comment.

[email protected]

Bug: N/A
Change-Id: I868ac9fad7e63df251d6c4b0d0ac8b099b81d25b
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue May 17, 2023
This CL is a follow-up to https://crrev.com/c/3936785 and
whatwg/html#6813 (comment). It
adds a test asserting the document state preservation as described more
below, in the `location.reload()` case, alongside a very similar test
that asserts the same for the document repopulation case.

The HTML Standard specifies the behavior of `location.reload()` to
preserve the existing history entry's document state's initiator origin
and referrer, as described in:
https://html.spec.whatwg.org/multipage/browsing-the-web.html#apply-the-history-step:~:text=If%20targetEntry%27s%20document%20is%20null%2C%20or%20targetEntry%27s%20document%20state%27s%20reload%20pending%20is%20true%2C%20then.

This means that when a page is navigated to from a cross-origin
predecessor, and then `location.reload()`s itself, `Sec-Fetch-Site`
should be `cross-site` and the `Referer` header should remain the same
as the original navigation.

Chromium currently fails this test, per
whatwg/html#6813 (comment) and
the code pointer described by that comment.

[email protected]

Bug: N/A
Change-Id: I868ac9fad7e63df251d6c4b0d0ac8b099b81d25b
aarongable pushed a commit to chromium/chromium that referenced this issue May 18, 2023
This CL is a follow-up to https://crrev.com/c/3936785 and
whatwg/html#6813 (comment). It
adds a test asserting the document state preservation as described more
below, in the `location.reload()` case, alongside a very similar test
that asserts the same for the document repopulation case.

The HTML Standard specifies the behavior of `location.reload()` to
preserve the existing history entry's document state's initiator origin
and referrer, as described in:
https://html.spec.whatwg.org/multipage/browsing-the-web.html#apply-the-history-step:~:text=If%20targetEntry%27s%20document%20is%20null%2C%20or%20targetEntry%27s%20document%20state%27s%20reload%20pending%20is%20true%2C%20then.

This means that when a page is navigated to from a cross-origin
predecessor, and then `location.reload()`s itself, `Sec-Fetch-Site`
should be `cross-site` and the `Referer` header should remain the same
as the original navigation.

Chromium currently fails this test, per
whatwg/html#6813 (comment) and
the code pointer described by that comment.

[email protected]

Bug: N/A
Change-Id: I868ac9fad7e63df251d6c4b0d0ac8b099b81d25b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4504799
Commit-Queue: Domenic Denicola <[email protected]>
Auto-Submit: Dominic Farolino <[email protected]>
Reviewed-by: Domenic Denicola <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1145759}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue May 18, 2023
This CL is a follow-up to https://crrev.com/c/3936785 and
whatwg/html#6813 (comment). It
adds a test asserting the document state preservation as described more
below, in the `location.reload()` case, alongside a very similar test
that asserts the same for the document repopulation case.

The HTML Standard specifies the behavior of `location.reload()` to
preserve the existing history entry's document state's initiator origin
and referrer, as described in:
https://html.spec.whatwg.org/multipage/browsing-the-web.html#apply-the-history-step:~:text=If%20targetEntry%27s%20document%20is%20null%2C%20or%20targetEntry%27s%20document%20state%27s%20reload%20pending%20is%20true%2C%20then.

This means that when a page is navigated to from a cross-origin
predecessor, and then `location.reload()`s itself, `Sec-Fetch-Site`
should be `cross-site` and the `Referer` header should remain the same
as the original navigation.

Chromium currently fails this test, per
whatwg/html#6813 (comment) and
the code pointer described by that comment.

[email protected]

Bug: N/A
Change-Id: I868ac9fad7e63df251d6c4b0d0ac8b099b81d25b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4504799
Commit-Queue: Domenic Denicola <[email protected]>
Auto-Submit: Dominic Farolino <[email protected]>
Reviewed-by: Domenic Denicola <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1145759}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue May 18, 2023
This CL is a follow-up to https://crrev.com/c/3936785 and
whatwg/html#6813 (comment). It
adds a test asserting the document state preservation as described more
below, in the `location.reload()` case, alongside a very similar test
that asserts the same for the document repopulation case.

The HTML Standard specifies the behavior of `location.reload()` to
preserve the existing history entry's document state's initiator origin
and referrer, as described in:
https://html.spec.whatwg.org/multipage/browsing-the-web.html#apply-the-history-step:~:text=If%20targetEntry%27s%20document%20is%20null%2C%20or%20targetEntry%27s%20document%20state%27s%20reload%20pending%20is%20true%2C%20then.

This means that when a page is navigated to from a cross-origin
predecessor, and then `location.reload()`s itself, `Sec-Fetch-Site`
should be `cross-site` and the `Referer` header should remain the same
as the original navigation.

Chromium currently fails this test, per
whatwg/html#6813 (comment) and
the code pointer described by that comment.

[email protected]

Bug: N/A
Change-Id: I868ac9fad7e63df251d6c4b0d0ac8b099b81d25b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4504799
Commit-Queue: Domenic Denicola <[email protected]>
Auto-Submit: Dominic Farolino <[email protected]>
Reviewed-by: Domenic Denicola <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1145759}
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue May 25, 2023
…t, a=testonly

Automatic update from web-platform-tests
Add location.reload() document state test

This CL is a follow-up to https://crrev.com/c/3936785 and
whatwg/html#6813 (comment). It
adds a test asserting the document state preservation as described more
below, in the `location.reload()` case, alongside a very similar test
that asserts the same for the document repopulation case.

The HTML Standard specifies the behavior of `location.reload()` to
preserve the existing history entry's document state's initiator origin
and referrer, as described in:
https://html.spec.whatwg.org/multipage/browsing-the-web.html#apply-the-history-step:~:text=If%20targetEntry%27s%20document%20is%20null%2C%20or%20targetEntry%27s%20document%20state%27s%20reload%20pending%20is%20true%2C%20then.

This means that when a page is navigated to from a cross-origin
predecessor, and then `location.reload()`s itself, `Sec-Fetch-Site`
should be `cross-site` and the `Referer` header should remain the same
as the original navigation.

Chromium currently fails this test, per
whatwg/html#6813 (comment) and
the code pointer described by that comment.

[email protected]

Bug: N/A
Change-Id: I868ac9fad7e63df251d6c4b0d0ac8b099b81d25b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4504799
Commit-Queue: Domenic Denicola <[email protected]>
Auto-Submit: Dominic Farolino <[email protected]>
Reviewed-by: Domenic Denicola <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1145759}

--

wpt-commits: d9c2152bab4d2933e38c8df3c95d967c40809f8c
wpt-pr: 39878
ErichDonGubler pushed a commit to erichdongubler-mozilla/firefox that referenced this issue May 27, 2023
…t, a=testonly

Automatic update from web-platform-tests
Add location.reload() document state test

This CL is a follow-up to https://crrev.com/c/3936785 and
whatwg/html#6813 (comment). It
adds a test asserting the document state preservation as described more
below, in the `location.reload()` case, alongside a very similar test
that asserts the same for the document repopulation case.

The HTML Standard specifies the behavior of `location.reload()` to
preserve the existing history entry's document state's initiator origin
and referrer, as described in:
https://html.spec.whatwg.org/multipage/browsing-the-web.html#apply-the-history-step:~:text=If%20targetEntry%27s%20document%20is%20null%2C%20or%20targetEntry%27s%20document%20state%27s%20reload%20pending%20is%20true%2C%20then.

This means that when a page is navigated to from a cross-origin
predecessor, and then `location.reload()`s itself, `Sec-Fetch-Site`
should be `cross-site` and the `Referer` header should remain the same
as the original navigation.

Chromium currently fails this test, per
whatwg/html#6813 (comment) and
the code pointer described by that comment.

[email protected]

Bug: N/A
Change-Id: I868ac9fad7e63df251d6c4b0d0ac8b099b81d25b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4504799
Commit-Queue: Domenic Denicola <[email protected]>
Auto-Submit: Dominic Farolino <[email protected]>
Reviewed-by: Domenic Denicola <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1145759}

--

wpt-commits: d9c2152bab4d2933e38c8df3c95d967c40809f8c
wpt-pr: 39878
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this issue May 31, 2023
…t, a=testonly

Automatic update from web-platform-tests
Add location.reload() document state test

This CL is a follow-up to https://crrev.com/c/3936785 and
whatwg/html#6813 (comment). It
adds a test asserting the document state preservation as described more
below, in the `location.reload()` case, alongside a very similar test
that asserts the same for the document repopulation case.

The HTML Standard specifies the behavior of `location.reload()` to
preserve the existing history entry's document state's initiator origin
and referrer, as described in:
https://html.spec.whatwg.org/multipage/browsing-the-web.html#apply-the-history-step:~:text=If%20targetEntry%27s%20document%20is%20null%2C%20or%20targetEntry%27s%20document%20state%27s%20reload%20pending%20is%20true%2C%20then.

This means that when a page is navigated to from a cross-origin
predecessor, and then `location.reload()`s itself, `Sec-Fetch-Site`
should be `cross-site` and the `Referer` header should remain the same
as the original navigation.

Chromium currently fails this test, per
whatwg/html#6813 (comment) and
the code pointer described by that comment.

R=domenicchromium.org

Bug: N/A
Change-Id: I868ac9fad7e63df251d6c4b0d0ac8b099b81d25b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4504799
Commit-Queue: Domenic Denicola <domenicchromium.org>
Auto-Submit: Dominic Farolino <domchromium.org>
Reviewed-by: Domenic Denicola <domenicchromium.org>
Cr-Commit-Position: refs/heads/main{#1145759}

--

wpt-commits: d9c2152bab4d2933e38c8df3c95d967c40809f8c
wpt-pr: 39878

UltraBlame original commit: 2342752e35cc28fc870b3576d5d7a22b9f92e7fd
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this issue May 31, 2023
…t, a=testonly

Automatic update from web-platform-tests
Add location.reload() document state test

This CL is a follow-up to https://crrev.com/c/3936785 and
whatwg/html#6813 (comment). It
adds a test asserting the document state preservation as described more
below, in the `location.reload()` case, alongside a very similar test
that asserts the same for the document repopulation case.

The HTML Standard specifies the behavior of `location.reload()` to
preserve the existing history entry's document state's initiator origin
and referrer, as described in:
https://html.spec.whatwg.org/multipage/browsing-the-web.html#apply-the-history-step:~:text=If%20targetEntry%27s%20document%20is%20null%2C%20or%20targetEntry%27s%20document%20state%27s%20reload%20pending%20is%20true%2C%20then.

This means that when a page is navigated to from a cross-origin
predecessor, and then `location.reload()`s itself, `Sec-Fetch-Site`
should be `cross-site` and the `Referer` header should remain the same
as the original navigation.

Chromium currently fails this test, per
whatwg/html#6813 (comment) and
the code pointer described by that comment.

R=domenicchromium.org

Bug: N/A
Change-Id: I868ac9fad7e63df251d6c4b0d0ac8b099b81d25b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4504799
Commit-Queue: Domenic Denicola <domenicchromium.org>
Auto-Submit: Dominic Farolino <domchromium.org>
Reviewed-by: Domenic Denicola <domenicchromium.org>
Cr-Commit-Position: refs/heads/main{#1145759}

--

wpt-commits: d9c2152bab4d2933e38c8df3c95d967c40809f8c
wpt-pr: 39878

UltraBlame original commit: 2342752e35cc28fc870b3576d5d7a22b9f92e7fd
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this issue May 31, 2023
…t, a=testonly

Automatic update from web-platform-tests
Add location.reload() document state test

This CL is a follow-up to https://crrev.com/c/3936785 and
whatwg/html#6813 (comment). It
adds a test asserting the document state preservation as described more
below, in the `location.reload()` case, alongside a very similar test
that asserts the same for the document repopulation case.

The HTML Standard specifies the behavior of `location.reload()` to
preserve the existing history entry's document state's initiator origin
and referrer, as described in:
https://html.spec.whatwg.org/multipage/browsing-the-web.html#apply-the-history-step:~:text=If%20targetEntry%27s%20document%20is%20null%2C%20or%20targetEntry%27s%20document%20state%27s%20reload%20pending%20is%20true%2C%20then.

This means that when a page is navigated to from a cross-origin
predecessor, and then `location.reload()`s itself, `Sec-Fetch-Site`
should be `cross-site` and the `Referer` header should remain the same
as the original navigation.

Chromium currently fails this test, per
whatwg/html#6813 (comment) and
the code pointer described by that comment.

R=domenicchromium.org

Bug: N/A
Change-Id: I868ac9fad7e63df251d6c4b0d0ac8b099b81d25b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4504799
Commit-Queue: Domenic Denicola <domenicchromium.org>
Auto-Submit: Dominic Farolino <domchromium.org>
Reviewed-by: Domenic Denicola <domenicchromium.org>
Cr-Commit-Position: refs/heads/main{#1145759}

--

wpt-commits: d9c2152bab4d2933e38c8df3c95d967c40809f8c
wpt-pr: 39878

UltraBlame original commit: 2342752e35cc28fc870b3576d5d7a22b9f92e7fd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interop Implementations are not interoperable with each other topic: history
Development

Successfully merging a pull request may close this issue.

3 participants