Skip to content
This repository was archived by the owner on Jul 30, 2019. It is now read-only.

Commit 8b477d2

Browse files
Alex Danilochaals
authored andcommitted
Referrer policy (#954)
* Added note that removes the restriction of <style> in <head> but pointing out that use in the body can trigger unwanted side effects. See Issue #544. * Added style to the set of flow content elements. * Partial commit for adding referrerpolicy. * Hard set for non-binary on the .include files, fixes merge pain. * Added attribute to stop git treating text files as binary. * Added referrer policy attribute for link reference resource fetch * Ported the commits from issue #560. Next, find other commits that this needs for completeness (attribute defs, IDL, etc.) * Addded definition section for referrer policy * Added a few more referrerpolicy references. * Bulk of referrerpolicy changes, check in for backup in reality. * Fixed up a bunch of link errors. * Fixed a few more linking errors, fixed typo. * Changes as per review, plus some markup cleanup.
1 parent a8c68cd commit 8b477d2

13 files changed

+204
-27
lines changed

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# - Deny applying with `git apply --whitespace=error-all`.
1313
# - Fix automatically with `git apply --whitespace=fix`.
1414
###############################################################################
15-
[attr]cleantext text eol=crlf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=4
15+
[attr]cleantext text eol=crlf whitespace=blank-at-eol,-blank-at-eof,-space-before-tab,tab-in-indent,tabwidth=4 -binary
1616

1717
###############################################################################
1818
# DEFAULT VALUE

sections/attributes.include

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,12 @@
600600
<td>Whether to allow the value to be edited by the user</td>
601601
<td><a>Boolean attribute</a></td>
602602
</tr>
603+
<tr>
604+
<th><code>referrerpolicy</code></th>
605+
<td><{a}>; <{area}>; <{iframe}>; <{img}>; <{link}></td>
606+
<td><a>Referrer policy</a> for <a>fetches</a> initiated by the element</td>
607+
<td><a>Referrer policy</a></td>
608+
</tr>
603609
<tr>
604610
<th><{links/rel}></th>
605611
<td><{a}>; <{area}>; <{link}></td>

sections/browsers.include

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3944,14 +3944,17 @@
39443944
<var>window</var>.
39453945
4. Set the {{Document}}'s <a for="document">HTTPS state</a> to the
39463946
[=response/HTTPS state=] of the resource used to generate the document.
3947-
5. Execute the <a>Initialize a <code>Document</code>'s CSP list</a> algorithm on the {{Document}}
3947+
5. Set the {{Document}}'s <a>referrer policy</a> to the result of
3948+
parsing the <a><code>Referrer-Policy</code></a> header</a> of the <a>response</a>
3949+
used to generate the document. [[!REFERRERPOLICY]]
3950+
6. Execute the <a>Initialize a <code>Document</code>'s CSP list</a> algorithm on the {{Document}}
39483951
object and the resource used to generate the document. [[CSP3]]
3949-
6. Set [=the document's referrer=] to the
3952+
7. Set [=the document's referrer=] to the
39503953
<em>address of the resource from which Request-URIs are obtained</em> as determined when the
39513954
fetch algorithm obtained the resource, if that algorithm was used and determined such a value;
39523955
otherwise, set it to the empty string.
3953-
7. <a>Implement the sandboxing</a> for the {{Document}}.
3954-
8. If the <a>active sandboxing flag set</a> of the {{Document}}'s <a>browsing context</a> or any
3956+
8. <a>Implement the sandboxing</a> for the {{Document}}.
3957+
9. If the <a>active sandboxing flag set</a> of the {{Document}}'s <a>browsing context</a> or any
39553958
of its <a>ancestor browsing contexts</a> (if any) have the
39563959
<a>sandboxed fullscreen browsing context flag</a> set, then skip this step.
39573960

sections/elements.include

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
<{links/download}>;
3030
<{links/rel}>;
3131
<{links/hreflang}>;
32-
<{links/type}></td>
32+
<{links/type}>;
33+
<{link/referrerpolicy}></td>
3334
<td>{{HTMLAnchorElement}}</td>
3435
</tr>
3536

@@ -70,7 +71,8 @@
7071
<{links/download}>;
7172
<{links/rel}>;
7273
<{links/hreflang}>;
73-
<{links/type}></td>
74+
<{links/type}>;
75+
<{link/referrerpolicy}></td>
7476
<td>{{HTMLAreaElement}}</td>
7577
</tr>
7678

@@ -608,7 +610,8 @@
608610
<{iframe/sandbox}>;
609611
<{iframe/allowfullscreen}>;
610612
<{media/width}>;
611-
<{media/height}></td>
613+
<{media/height}>;
614+
<{iframe/referrerpolicy}></td>
612615
<td>{{HTMLIFrameElement}}</td>
613616
</tr>
614617

@@ -631,7 +634,8 @@
631634
<{img/ismap}>;
632635
<{img/longdesc}>;
633636
<{media/width}>;
634-
<{media/height}></td>
637+
<{media/height}>;
638+
<{img/referrerpolicy}></td>
635639
<td>{{HTMLImageElement}}</td>
636640
</tr>
637641

@@ -765,6 +769,7 @@
765769
<{link/crossorigin}>;
766770
<{link/rel}>;
767771
<{link/media}>;
772+
<{link/referrerpolicy}>;
768773
<{link/nonce}>;
769774
<{link/hreflang}>;
770775
<{link/type}>;

sections/infrastructure.include

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@
166166
A <dfn for="document" lt="inserted into|inserted into the document|inserted into a document">node
167167
is inserted into a document</dfn> when the <a>insertion steps</a> are invoked with it as the
168168
argument and it is now <a>in a document tree</a>. Analogously, a
169-
<dfn for="document" lt="remove an element from a document|removed from a document|removed from">node
169+
<dfn for="document" lt="remove an element from a document|removed from a document|removed from the document|removed from">node
170170
is removed from a document</dfn> when the <a>removing steps</a> are invoked with it as the argument
171171
and it is now no longer in a <a>document tree</a>.
172172

@@ -712,8 +712,18 @@
712712
* <a for="request">cache mode</a>
713713
* <a for="request">redirect mode</a>
714714
* <a>cryptographic nonce metadata</a>
715+
* <a for="request">referrer policy</a>
715716
* <a>parser metadata</a>
716717

718+
:: The following terms are defined in <cite>Referrer Policy</cite> [[!REFERRERPOLICY]]
719+
720+
* <a for="request">referrer policy</a>
721+
* The <dfn>`Referrer-Policy`</dfn> HTTP header
722+
* The <dfn>parse a referrer policy from a <code>`Referrer-Policy`</code> header</dfn> algorithm
723+
* The "<dfn><code>no-referrer</code></dfn>",
724+
"<dfn><code>no-referrer-when-downgrade</code></dfn>", and
725+
"<dfn><code>unsafe-url</code></dfn>" referrer policies
726+
717727
: Web IDL
718728
:: The IDL fragments in this specification must be interpreted as required for conforming IDL
719729
fragments, as described in the Web IDL specification. [[!WEBIDL]]
@@ -3770,6 +3780,33 @@
37703780
<i>missing value default</i>, used when the attribute is omitted, is the
37713781
<dfn state for="cors">No CORS</dfn> state.
37723782

3783+
<h4 id="referrer-policy-attributes">Referrer policy attributes</h4>
3784+
3785+
A <dfn export="">referrer policy attribute</dfn> is an <a>enumerated attribute</a>.
3786+
Each <a>referrer policy</a>, including the empty string, is a keyword for this attribute,
3787+
mapping to a state of the same name.
3788+
3789+
The attribute's <a>invalid value default</a> and <a>missing value default</a>
3790+
are both the empty string state.
3791+
3792+
The impact of these states on the processing model of various <a>fetches</a> is defined
3793+
in more detail throughout this specification, in the WHATWG Fetch standard, and in <cite>Referrer Policy</cite>.
3794+
[[!FETCH]] [[!REFERRERPOLICY]]
3795+
3796+
<div class="note">
3797+
Several signals can contribute to which processing model is used for a given <a>fetch</a>;
3798+
a <a>referrer policy attribute</a> is only one of them. In general, the order in which these signals are processed are:
3799+
<ol>
3800+
<li>First, the presence of a <{link/}noreferrer}> link
3801+
type;</li>
3802+
<li>Then, the value of a <a>referrer policy attribute</a>;</li>
3803+
<li>Then, the presence of any <{meta}> element with <a><code
3804+
for="attr-meta-name">name</code></a> attribute set to <a><code>referrer</code></a>.</li>
3805+
<li>Finally, the <code>`Referrer-Policy`</code> HTTP
3806+
header.</li>
3807+
</ol>
3808+
</div>
3809+
37733810
<h3 id="common-dom-interfaces">Common DOM interfaces</h3>
37743811

37753812
<h4 id="reflecting-content-attributes-in-idl-attributes">Reflecting content attributes in IDL attributes</h4>

sections/semantics-document-metadata.include

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@
332332
<dd><code>nonce</code> — Cryptographic nonce used in Content Security Policy checks [[CSP3]]</dd>
333333
<dd><code>hreflang</code> — Language of the linked resource</dd>
334334
<dd><code>type</code> — Hint for the type of the referenced resource</dd>
335+
<dd><code>referrerpolicy</code> - <a>Referrer policy</a> for <a>fetches</a> initiated by the element</dd>
335336
<dd><code>sizes</code> — Sizes of the icons (for <{link/rel}>="<code>icon</code>")</dd>
336337
<dd>
337338
Also, the <{link/title}> attribute has special semantics on this element: Title of the
@@ -357,7 +358,8 @@
357358
[CEReactions] attribute DOMString hreflang;
358359
[CEReactions] attribute DOMString type;
359360
[CEReactions, SameObject, PutForwards=value] readonly attribute DOMTokenList sizes;
360-
};
361+
[CEReactions] attribute DOMString referrerPolicy;
362+
};
361363
HTMLLinkElement implements LinkStyle;
362364
</pre>
363365
</dd>
@@ -463,7 +465,10 @@
463465
For <a>external resource links</a>, the <{link/type}> attribute is used as a hint to user agents
464466
so that they can avoid fetching resources they do not support.
465467

466-
<!-- def <{link/referrerpolicy}> -->
468+
The <dfn element-attr for="link"><code>referrerpolicy</code></dfn> attribute is a
469+
<a>referrer policy attribute</a>. It is intended for use with <a>external resource links</a>,
470+
where it helps set the <a>referrer policy</a> used when <a>obtaining</a> the external resource.
471+
[[!REFERRERPOLICY]].
467472

468473
The <dfn element-attr for="link"><code>title</code></dfn> attribute gives the title of the link.
469474
With one exception, it is purely advisory. The value is text. The exception is for style sheet
@@ -525,6 +530,10 @@
525530

526531
<!-- def {{HTMLLinkElement/referrerPolicy}} -->
527532

533+
The <dfn attribute for="HTMLLinkElement"><code>referrerPolicy</code></dfn> IDL attribute must
534+
<a>reflect</a> the <code>referrerpolicy</code>
535+
content attribute, <a>limited to only known values</a>.
536+
528537
The IDL attribute <dfn attribute for="HTMLLinkElement"><code>relList</code></dfn> must
529538
<a>reflect</a> the <{link/rel}> content attribute.
530539

@@ -630,7 +639,9 @@
630639
{{Window}} object's <a>environment settings object</a>.
631640
6. Set <var>request</var>'s <a>cryptographic nonce metadata</a> to the current state of the
632641
<{link}> element's <{link/nonce}> content attribute.
633-
7. <a>Fetch</a> <var>request</var>.
642+
7. Set <var>request</var>'s <a>referrer policy</a> to the current state of the
643+
<{link}> element's <{link/referrerpolicy}> content attribute.
644+
8. <a>Fetch</a> <var>request</var>.
634645

635646
User agents may opt to only try to obtain such resources when they are needed, instead of
636647
pro-actively fetching all the external resources that are not applied.
@@ -963,6 +974,63 @@
963974
inappropriate keywords.
964975
</p>
965976

977+
: <dfn><code>referrer</code></dfn>
978+
979+
:: The value must be a <a>referrer policy</a>, which defines the default
980+
<a>referrer policy</a> for the <code>Document</code>. [[!REFERRERPOLICY]]
981+
982+
If any <code>meta</code> elements are <a>inserted into the document</a> or
983+
<a>removed from the document</a>, or existing <code>meta</code> elements have their <code>name</code>
984+
or <code>content</code> attributes changed, user agents must run the following algorithm:
985+
986+
1. <p>Let <var>candidate elements</var> be the list of all <code>meta</code> elements that
987+
meet the following criteria, in <a>tree order</a>:</p>
988+
989+
<ul class="brief">
990+
<li>The element is <a>in a document tree</a></li>
991+
<li>The element has a <code>name</code> attribute, whose value is <code>referrer</code></li>
992+
<li>The element has a <code>content</code> attribute, whose value is not the empty string</li>
993+
<li>The element is a child of the <{head}> element of the document</li>
994+
</ul>
995+
996+
2. For each <var>element</var> in <var>candidate elements</var>:
997+
998+
1. <p>Let <var>value</var> be the value of <var>element</var>'s <code>content</code> attribute,
999+
converted to [=ASCII lowercase=].</p></li>
1000+
1001+
2. <p>If <var>value</var> is one of the values given in the first column of the following
1002+
table, then set <var>value</var> to the value given in the second column:</p>
1003+
1004+
<table>
1005+
<thead>
1006+
<tr>
1007+
<th>Legacy value
1008+
<th>Referrer policy
1009+
<tbody>
1010+
<tr>
1011+
<td><code>never</code>
1012+
<td><code>no-referrer</code>
1013+
<tr>
1014+
<td><code>default</code>
1015+
<td><code>no-referrer-when-downgrade</code>
1016+
<tr>
1017+
<td><code>always</code>
1018+
<td><code>unsafe-url</code>
1019+
<tr>
1020+
<td><code>origin-when-crossorigin</code>
1021+
<td><code>origin-when-cross-origin</code>
1022+
</table>
1023+
1024+
3. <p>If <var>value</var> is a <a>referrer policy</a>, then set <var>element</var>'s
1025+
<a>node document</a>'s <a>referrer policy</a> to <var>policy</var>.</p>
1026+
1027+
1028+
<p class="note">The fact that these steps are applied for each element enables <a
1029+
href="https://w3c.github.io/webappsec-referrer-policy/#unknown-policy-values">deployment of
1030+
fallback values for older user agents</a>. [[!REFERRERPOLICY]]</p>
1031+
1032+
</div>
1033+
9661034
<h5 id="other-metadata-names">Other metadata names</h5>
9671035

9681036
<dfn lt="register the names|register the name|metadata names">Extensions to the predefined set of metadata names</dfn> may be registered in the

0 commit comments

Comments
 (0)