You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<aclass="self-link" href="#example-55395680"></a> MegaCorp Inc. hosts a number of pages on <code>http://non-secure.example.com</code> which need to write cookies, but don’t need those cookies to span
1086
+
<divclass="example" id="example-3070c811">
1087
+
<aclass="self-link" href="#example-3070c811"></a> MegaCorp Inc. hosts a number of pages on <code>http://non-secure.example.com</code> which need to write cookies, but don’t need those cookies to span
1083
1088
subdomains. The following header ensures that cookies can only be set via <code>Set-Cookie</code> or <code>document.cookie</code> if those cookies are "host only" (e.g. the
<aclass="self-link" href="#example-b4774c33"></a> MegaCorp Inc. hosts a number of pages on <code>https://secure.example.com</code> which need to write cookies, but don’t need those cookies to span
1099
+
<divclass="example" id="example-e1a66362">
1100
+
<aclass="self-link" href="#example-e1a66362"></a> MegaCorp Inc. hosts a number of pages on <code>https://secure.example.com</code> which need to write cookies, but don’t need those cookies to span
1090
1101
subdomains. They’ll certainly set the <adata-link-type="grammar" href="#grammardef-host">host</a> property, just
1091
1102
like the previous example, but since this is a secure site, they also wish
1092
1103
to ensure that any cookies they set also contain the <code>secure</code> attribute.
<p><dfndata-dfn-type="dfn" data-export="" id="cookie-scope"><code>cookie-scope</code><aclass="self-link" href="#cookie-scope"></a></dfn> is a Content Security Policy <adata-link-type="dfn" href="https://mikewest.github.io/webappsec/specs/content-security-policy/#directive">directive</a><adata-link-type="biblio" href="#biblio-csp">[CSP]</a> which restricts the scope in which <adata-link-type="dfn" href="https://tools.ietf.org/html/rfc6265#section-1">cookies</a><adata-link-type="biblio" href="#biblio-rfc6265">[RFC6265]</a> can be set. The syntax is described by the following ABNF
1101
-
grammar:</p>
1119
+
grammar<adata-link-type="biblio" href="#biblio-rfc5234">[RFC5234]</a> (including the <adata-link-type="grammar" href="https://tools.ietf.org/html/rfc7230#section-3.2.3">RWS</a> rule from <adata-link-type="biblio" href="#biblio-rfc7230">[RFC7230]</a>:</p>
<p>"<adata-link-type="grammar" href="#grammardef-host">host</a>" allows "host only" cookies to be set, but will block
1128
+
setting cookies which set a <code>domain</code> attribute.</p>
1129
+
<lidata-md="">
1130
+
<p>"<adata-link-type="grammar" href="#grammardef-none">none</a>" blocks all cookies.</p>
1131
+
<lidata-md="">
1132
+
<p>"<adata-link-type="grammar" href="#grammardef-secure">secure</a>" allows cookies to be set with a <code>secure</code> attribute, and will block setting any non-secure cookies.</p>
1133
+
</ol>
1134
+
<p>These values MAY be combined in order to tighten the restrictions on a cookie.
1135
+
That is, if both "<adata-link-type="grammar" href="#grammardef-host">host</a>" and "<adata-link-type="grammar" href="#grammardef-secure">secure</a>" are
1136
+
present, then cookies may only be set which are both secure and host-only.
1137
+
If "<adata-link-type="grammar" href="#grammardef-none">none</a>" is present with any combination of the other values,
1138
+
no cookies may be set.</p>
1106
1139
<pclass="issue" id="issue-6a48c646"><aclass="self-link" href="#issue-6a48c646"></a> Erik Nygren <ahref="https://lists.w3.org/Archives/Public/public-webappsec/2013Sep/0046.html">proposed</a> adding <code>path</code> restrictions as well. Is that worthwhile?</p>
1107
-
<h3class="heading settled" data-level="2.1" id="monkey-patching-rfc6264"><spanclass="secno">2.1. </span><spanclass="content">Enforcement and Monitoring</span><aclass="self-link" href="#monkey-patching-rfc6264"></a></h3>
<p>After step 10 of <ahref="https://tools.ietf.org/html/rfc6265#section-5.3">the
1109
1142
storage algorithm in Section 5.3 of RFC 6265</a>, a cookie object has been
1110
-
built. Insert the following validation steps before proceeding to the current
1143
+
built. Insert the following validation step before proceeding to the current
1111
1144
step 11:</p>
1112
1145
<olstart="11">
1113
1146
<li> If <ahref="#block-cookie">§3.1 Is cookie blocked for settings object?</a> returns "<code>Blocked</code>" when executed upon <var>cookie</var> and the <adata-link-type="dfn" href="http://www.w3.org/TR/html5/webappapis.html#incumbent-settings-object">incumbent settings object</a>,
<p>Let <var>scope</var> be the value of <var>policy</var>’s <adata-link-type="dfn" href="#cookie-scope">cookie-scope</a> directive.</p>
1185
+
<p>Let <var>scope</var> be the result of executing <ahref="#parse">§3.3 Parse string as a cookie-scope value</a> on<var>policy</var>’s <adata-link-type="dfn" href="#cookie-scope">cookie-scope</a> directive.</p>
1153
1186
<lidata-md="">
1154
1187
<p>If any of the following conditions are met, return "<code>Violates</code>":</p>
<h3class="heading settled" data-level="3.3" id="parse"><spanclass="secno">3.3. </span><spanclass="content"> Parse <var>string</var> as a <code>cookie-scope</code> value </span><aclass="self-link" href="#parse"></a></h3>
1201
+
<p>Given a string (<var>string</var>), this algorithm returns a set of the valid <adata-link-type="dfn" href="#cookie-scope"><code>cookie-scope</code></a> values the string represents. Invalid values are
1202
+
ignored:</p>
1203
+
<ol>
1204
+
<lidata-md="">
1205
+
<p><adata-link-type="dfn" href="http://www.w3.org/TR/html5/infrastructure.html#strip-leading-and-trailing-whitespace">Strip leading and trailing whitespace</a> from <var>string</var>.</p>
1206
+
<lidata-md="">
1207
+
<p>Let <var>values</var> be an empty set.</p>
1208
+
<lidata-md="">
1209
+
<p>For each <var>token</var> in the list generated by <adata-link-type="dfn" href="http://www.w3.org/TR/html5/infrastructure.html#split-a-string-on-spaces">splitting <var>string</var> on
1210
+
spaces</a>:</p>
1211
+
<ol>
1212
+
<lidata-md="">
1213
+
<p>If <var>token</var> matches the grammar for <adata-link-type="grammar" href="#grammardef-scoping-rules">scoping-rules</a>, insert <var>token</var> into <var>values</var>.</p>
<dd>Roy T. Fielding; Julian F. Reschke. <ahref="http://www.ietf.org/rfc/rfc7230.txt">HTTP/1.1 Message Syntax and Routing</a>. RFC. URL: <ahref="http://www.ietf.org/rfc/rfc7230.txt">http://www.ietf.org/rfc/rfc7230.txt</a>
<dd>Anne van Kesteren. <ahref="https://url.spec.whatwg.org/">URL</a>. Living Standard. URL: <ahref="https://url.spec.whatwg.org/">https://url.spec.whatwg.org/</a>
<dd>S. Bradner. <ahref="https://tools.ietf.org/html/rfc2119">Key words for use in RFCs to Indicate Requirement Levels</a>. March 1997. Best Current Practice. URL: <ahref="https://tools.ietf.org/html/rfc2119">https://tools.ietf.org/html/rfc2119</a>
<dd>D. Crocker, Ed.; P. Overell. <ahref="https://tools.ietf.org/html/rfc5234">Augmented BNF for Syntax Specifications: ABNF</a>. January 2008. Internet Standard. URL: <ahref="https://tools.ietf.org/html/rfc5234">https://tools.ietf.org/html/rfc5234</a>
<dd>M. Nottingham. <ahref="https://tools.ietf.org/html/rfc7320">URI Design and Ownership</a>. July 2014. Best Current Practice. URL: <ahref="https://tools.ietf.org/html/rfc7320">https://tools.ietf.org/html/rfc7320</a>
0 commit comments