Skip to content

Support nonce & referrer-policy in preload & link headers#7961

Merged
domenic merged 6 commits intowhatwg:mainfrom
noamr:preload-referrer-policy
Jun 2, 2022
Merged

Support nonce & referrer-policy in preload & link headers#7961
domenic merged 6 commits intowhatwg:mainfrom
noamr:preload-referrer-policy

Conversation

@noamr
Copy link
Copy Markdown
Collaborator

@noamr noamr commented May 27, 2022

In preparation for supporting [modulepreload](whatwg#7862) in link headers.

- Parse `referrerpolicy` from link headers
- Add referrer policy and nonce to link processing optinos
@noamr noamr changed the title Support nonce & referrerpolicy in preload & link headers Support nonce & referrer-policy in preload & link headers May 27, 2022
Copy link
Copy Markdown
Member

@domenic domenic left a comment

Choose a reason for hiding this comment

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

This seems like a great idea to me. Maybe @domfarolino could comment with Chromium implementer interest?

Is there a need to include any of these in the preload key? Referrer policy especially seems potentially worthwhile... although perhaps tricky, because the current behavior is to just not require a match, so there might be a compat issue in starting to require a match?

@domenic domenic added addition/proposal New features or enhancements topic: link labels May 31, 2022
@noamr
Copy link
Copy Markdown
Collaborator Author

noamr commented Jun 1, 2022

This seems like a great idea to me. Maybe @domfarolino could comment with Chromium implementer interest?

Is there a need to include any of these in the preload key? Referrer policy especially seems potentially worthwhile...
although perhaps tricky, because the current behavior is to just not require a match, so there might be a compat issue in starting to require a match?

I wouldn't suggest requiring a match for referrer policy. It's tricky in many ways. A mismatch in referrer policy could still be a match in referrer, and a match in referrer policy can still be a mismatch in referrer (e.g. a font will have the containing style as referrer)

Either way, I wanted first to align link headers with link elements, and perhaps we can discuss changing the preload matching mechanism in a subsequent issue?

@domenic
Copy link
Copy Markdown
Member

domenic commented Jun 1, 2022

Either way, I wanted first to align link headers with link elements, and perhaps we can discuss changing the preload matching mechanism in a subsequent issue?

That seems reasonable, as long as we have tests showing that both link elements and link headers allow such mismatches.

@noamr
Copy link
Copy Markdown
Collaborator Author

noamr commented Jun 1, 2022

Either way, I wanted first to align link headers with link elements, and perhaps we can discuss changing the preload matching mechanism in a subsequent issue?

That seems reasonable, as long as we have tests showing that both link elements and link headers allow such mismatches.

I modified web-platform-tests/wpt#34245 to test this.

@domenic
Copy link
Copy Markdown
Member

domenic commented Jun 1, 2022

So right now it seems like attribute processing is split across a few places:

  • "create a link element request" reads [[CryptographicNonce]], integrity, and referrerpolicy directly from the element and puts them on the request.
  • But "create link options from element" reads [[CryptographicNonce]] and integrity (but not referrerpolicy) from the element

This seems bad? As far as I can tell this means we're using different codepaths for preconnect/preload ("create link options from element") vs. everything else ("create a link element request"). "Everything else" notably includes stylesheet, manifest, and modulepreload, although in theory any of the external resource links might be fetched by browsers.

I think at the very least "create link options from element" needs to include referrerpolicy, right?

Further unification would probably require using "create link options from element" for everything else, which I guess we should not do at this point. But it does indicate the name "link processing options" might be overly-broad since it only applies to preconnect/preload.

@noamr
Copy link
Copy Markdown
Collaborator Author

noamr commented Jun 1, 2022

So right now it seems like attribute processing is split across a few places:

  • "create a link element request" reads [[CryptographicNonce]], integrity, and referrerpolicy directly from the element and puts them on the request.
  • But "create link options from element" reads [[CryptographicNonce]] and integrity (but not referrerpolicy) from the element

This seems bad? As far as I can tell this means we're using different codepaths for preconnect/preload ("create link options from element") vs. everything else ("create a link element request"). "Everything else" notably includes stylesheet, manifest, and modulepreload, although in theory any of the external resource links might be fetched by browsers.

It's temporarily inconsistent (aka "bad"). modulepreload will also use create link options from element in a subsequent patch.

I think at the very least "create link options from element" needs to include referrerpolicy, right?

Right, it's a missing part that should go into this patch,

Further unification would probably require using "create link options from element" for everything else, which I guess we should not do at this point. But it does indicate the name "link processing options" might be overly-broad since it only applies to preconnect/preload.

If we decide to support further rels in link headers they would probably use the same struct. Not sure how else to call it

@domenic
Copy link
Copy Markdown
Member

domenic commented Jun 1, 2022

Yeah, I guess we'll leave any further clarification/renaming until at least #7890.

Copy link
Copy Markdown
Member

@domenic domenic left a comment

Choose a reason for hiding this comment

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

LGTM, including tests. This seems like it should be quite reasonable but I'd still love some confirmation from Chromium or WebKit before merging, in case there's some opposition. Let's try asking @yoavweiss in addition to @domfarolino, for Chromium...

@yoavweiss
Copy link
Copy Markdown
Contributor

Seems like nonce is already implemented and passing the tests. I can take on adding the ReferrerPolicy bits, if no one else does. /cc @yutakahirano

@domenic domenic merged commit 94a9b1d into whatwg:main Jun 2, 2022
@domfarolino
Copy link
Copy Markdown
Member

Back from vacation today. Yoav, feel free to take the referrer policy bits, otherwise I'm happy to do it if you do not have time.

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Jun 9, 2022
This CL adds `referrerpolicy` support to Link header preloads, and fixes
the related tests.

PR: whatwg/html#7961

Bug: i1330073
Change-Id: I0deb4afd6c77a2d766da8e706211195d6840b3a1
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Jun 9, 2022
This CL adds `referrerpolicy` support to Link header preloads, and fixes
the related tests.

PR: whatwg/html#7961

Bug: i1330073
Change-Id: I0deb4afd6c77a2d766da8e706211195d6840b3a1
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Jun 9, 2022
This CL adds `referrerpolicy` support to Link header preloads, and fixes
the related tests.

PR: whatwg/html#7961

Bug: 1330073
Change-Id: I0deb4afd6c77a2d766da8e706211195d6840b3a1
aarongable pushed a commit to chromium/chromium that referenced this pull request Jun 13, 2022
This CL adds `referrerpolicy` support to Link header preloads, and fixes
the related tests.

PR: whatwg/html#7961

Bug: 1330073
Change-Id: I0deb4afd6c77a2d766da8e706211195d6840b3a1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3698081
Reviewed-by: Yutaka Hirano <[email protected]>
Commit-Queue: Yoav Weiss <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1013370}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Jun 13, 2022
This CL adds `referrerpolicy` support to Link header preloads, and fixes
the related tests.

PR: whatwg/html#7961

Bug: 1330073
Change-Id: I0deb4afd6c77a2d766da8e706211195d6840b3a1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3698081
Reviewed-by: Yutaka Hirano <[email protected]>
Commit-Queue: Yoav Weiss <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1013370}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this pull request Jun 13, 2022
This CL adds `referrerpolicy` support to Link header preloads, and fixes
the related tests.

PR: whatwg/html#7961

Bug: 1330073
Change-Id: I0deb4afd6c77a2d766da8e706211195d6840b3a1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3698081
Reviewed-by: Yutaka Hirano <[email protected]>
Commit-Queue: Yoav Weiss <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1013370}
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Jun 14, 2022
…rt, a=testonly

Automatic update from web-platform-tests
Preload Link header referrerpolicy support

This CL adds `referrerpolicy` support to Link header preloads, and fixes
the related tests.

PR: whatwg/html#7961

Bug: 1330073
Change-Id: I0deb4afd6c77a2d766da8e706211195d6840b3a1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3698081
Reviewed-by: Yutaka Hirano <[email protected]>
Commit-Queue: Yoav Weiss <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1013370}

--

wpt-commits: 2d82c9ff94b451881ad3e3f5bc9b03d6b62719e8
wpt-pr: 34365
jamienicol pushed a commit to jamienicol/gecko that referenced this pull request Jun 16, 2022
…rt, a=testonly

Automatic update from web-platform-tests
Preload Link header referrerpolicy support

This CL adds `referrerpolicy` support to Link header preloads, and fixes
the related tests.

PR: whatwg/html#7961

Bug: 1330073
Change-Id: I0deb4afd6c77a2d766da8e706211195d6840b3a1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3698081
Reviewed-by: Yutaka Hirano <[email protected]>
Commit-Queue: Yoav Weiss <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1013370}

--

wpt-commits: 2d82c9ff94b451881ad3e3f5bc9b03d6b62719e8
wpt-pr: 34365
webkit-early-warning-system pushed a commit to charliewolfe/WebKit that referenced this pull request Oct 10, 2022
https://bugs.webkit.org/show_bug.cgi?id=241059
<rdar://94384756>

Reviewed by Darin Adler.

Added support for referrer-policy in link headers.
whatwg/html#7961

* Source/WebCore/loader/LinkHeader.cpp:
(WebCore::paramterNameFromString):
(WebCore::LinkHeader::setValue):
* Source/WebCore/loader/LinkHeader.h:
(WebCore::LinkHeader::referrerPolicy const):
* Source/WebCore/loader/LinkLoader.cpp:
(WebCore::LinkLoader::loadLinksFromHeader):
* LayoutTests/imported/w3c/web-platform-tests/preload/preload-referrer-policy-expected.txt: Added.
* LayoutTests/imported/w3c/web-platform-tests/preload/preload-referrer-policy.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/preload/resources/echo-referrer.py: Added.
(main):
* LayoutTests/imported/w3c/web-platform-tests/preload/resources/link-header-referrer-policy.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/preload/resources/link-header-referrer-policy.py: Added.
(main):

Canonical link: https://commits.webkit.org/255354@main
jwidar pushed a commit to jwidar/LatencyZeroGithub that referenced this pull request Sep 16, 2025
…rt, a=testonly

Automatic update from web-platform-tests
Preload Link header referrerpolicy support

This CL adds `referrerpolicy` support to Link header preloads, and fixes
the related tests.

PR: whatwg/html#7961

Bug: 1330073
Change-Id: I0deb4afd6c77a2d766da8e706211195d6840b3a1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3698081
Reviewed-by: Yutaka Hirano <[email protected]>
Commit-Queue: Yoav Weiss <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1013370}

--

wpt-commits: 2d82c9ff94b451881ad3e3f5bc9b03d6b62719e8
wpt-pr: 34365
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

addition/proposal New features or enhancements topic: link

Development

Successfully merging this pull request may close these issues.

4 participants