Skip to content

Commit ee2d941

Browse files
committed
CSP-COOKIES: Cleaning up for wider review.
1 parent 9a0090f commit ee2d941

File tree

2 files changed

+183
-27
lines changed

2 files changed

+183
-27
lines changed

specs/csp-cookies/index.html

Lines changed: 87 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -994,7 +994,7 @@
994994
<div class="head">
995995
<p data-fill-with="logo"></p>
996996
<h1 class="p-name no-ref" id="title">Content Security Policy: Cookie Controls</h1>
997-
<h2 class="no-num no-toc no-ref heading settled" id="subtitle"><span class="content">A Collection of Interesting Ideas, <time class="dt-updated" datetime="2015-09-25">25 September 2015</time></span></h2>
997+
<h2 class="no-num no-toc no-ref heading settled" id="subtitle"><span class="content">A Collection of Interesting Ideas, <time class="dt-updated" datetime="2015-09-26">26 September 2015</time></span></h2>
998998
<div data-fill-with="spec-metadata">
999999
<dl>
10001000
<dt>This version:
@@ -1011,10 +1011,9 @@ <h2 class="no-num no-toc no-ref heading settled" id="subtitle"><span class="cont
10111011
</div>
10121012
<h2 class="no-num no-toc no-ref heading settled" id="abstract"><span class="content">Abstract</span></h2>
10131013
<div class="p-summary" data-fill-with="abstract">
1014-
<p>This document defines several Content Security Policy directives which allow
1014+
<p>This document defines mechanisms by which web developers can limit the ways
10151015

1016-
web developers to limit the ways in which cookies may be set in the context
1017-
of a particular protected resource.</p>
1016+
in which cookies may be set in the context of their sites and applications.</p>
10181017
</div>
10191018
<div data-fill-with="at-risk"></div>
10201019
<h2 class="no-num no-toc no-ref heading settled" id="contents"><span class="content">Table of Contents</span></h2>
@@ -1028,15 +1027,21 @@ <h2 class="no-num no-toc no-ref heading settled" id="contents"><span class="cont
10281027
<li>
10291028
<a href="#cookie-scope-directive"><span class="secno">2</span> <span class="content">The <code>cookie-scope</code> directive</span></a>
10301029
<ul class="toc">
1031-
<li><a href="#monkey-patching-rfc6264"><span class="secno">2.1</span> <span class="content">Enforcement and Monitoring</span></a>
1030+
<li><a href="#monkey-patching-rfc6264"><span class="secno">2.1</span> <span class="content">Processing Model</span></a>
10321031
</ul>
10331032
<li>
10341033
<a href="#algorithms"><span class="secno">3</span> <span class="content">Algorithms</span></a>
10351034
<ul class="toc">
10361035
<li><a href="#block-cookie"><span class="secno">3.1</span> <span class="content"> Is <var>cookie</var> blocked for <var>settings object</var>? </span></a>
10371036
<li><a href="#violates"><span class="secno">3.2</span> <span class="content"> Does <var>cookie</var> violate <var>policy</var>? </span></a>
1037+
<li><a href="#parse"><span class="secno">3.3</span> <span class="content"> Parse <var>string</var> as a <code>cookie-scope</code> value </span></a>
10381038
</ul>
1039-
<li><a href="#acknowledgements"><span class="secno">4</span> <span class="content">Acknowledgements</span></a>
1039+
<li>
1040+
<a href="#security-considerations"><span class="secno">4</span> <span class="content">Security Considerations</span></a>
1041+
<ul class="toc">
1042+
<li><a href="#existing"><span class="secno">4.1</span> <span class="content">Existing Cookies</span></a>
1043+
</ul>
1044+
<li><a href="#acknowledgements"><span class="secno">5</span> <span class="content">Acknowledgements</span></a>
10401045
<li><a href="#conformance"><span class="secno"></span> <span class="content"> Conformance</span></a>
10411046
<li>
10421047
<a href="#index"><span class="secno"></span> <span class="content">Index</span></a>
@@ -1078,36 +1083,64 @@ <h3 class="heading settled" data-level="1.1" id="examples"><span class="secno">1
10781083
<pre><a data-link-type="dfn" href="https://mikewest.github.io/webappsec/specs/content-security-policy/#content_security_policy">Content-Security-Policy</a>: <a data-link-type="dfn" href="#cookie-scope">cookie-scope</a> <a data-link-type="grammar" href="#grammardef-none">none</a>
10791084
</pre>
10801085
</div>
1081-
<div class="example" id="example-55395680">
1082-
<a class="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+
<div class="example" id="example-3070c811">
1087+
<a class="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
10831088
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
10841089
cookie’s <code>domain</code> attribute is empty):
10851090
<pre><a data-link-type="dfn" href="https://mikewest.github.io/webappsec/specs/content-security-policy/#content_security_policy">Content-Security-Policy</a>: <a data-link-type="dfn" href="#cookie-scope">cookie-scope</a> <a data-link-type="grammar" href="#grammardef-host">host</a>
1091+
</pre>
1092+
<p>That is, the following code would set a cookie:</p>
1093+
<pre>document.cookie = "key=value";
1094+
</pre>
1095+
<p>And the following would not:</p>
1096+
<pre>document.cookie = "key=value; domain=example.com";
10861097
</pre>
10871098
</div>
1088-
<div class="example" id="example-b4774c33">
1089-
<a class="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+
<div class="example" id="example-e1a66362">
1100+
<a class="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
10901101
subdomains. They’ll certainly set the <a data-link-type="grammar" href="#grammardef-host">host</a> property, just
10911102
like the previous example, but since this is a secure site, they also wish
10921103
to ensure that any cookies they set also contain the <code>secure</code> attribute.
10931104
They can do so with the following header:
10941105
<pre><a data-link-type="dfn" href="https://mikewest.github.io/webappsec/specs/content-security-policy/#content_security_policy">Content-Security-Policy</a>: <a data-link-type="dfn" href="#cookie-scope">cookie-scope</a> <a data-link-type="grammar" href="#grammardef-host">host</a> <a data-link-type="grammar" href="#grammardef-secure">secure</a>
1106+
</pre>
1107+
<p>That is, the following code would set a cookie:</p>
1108+
<pre>document.cookie = "key=value; secure";
1109+
</pre>
1110+
<p>And the following would not:</p>
1111+
<pre>document.cookie = "key=value";
1112+
document.cookie = "key=value; domain=example.com; secure";
10951113
</pre>
10961114
</div>
10971115
</section>
10981116
<section>
10991117
<h2 class="heading settled" data-level="2" id="cookie-scope-directive"><span class="secno">2. </span><span class="content">The <code>cookie-scope</code> directive</span><a class="self-link" href="#cookie-scope-directive"></a></h2>
11001118
<p><dfn data-dfn-type="dfn" data-export="" id="cookie-scope"><code>cookie-scope</code><a class="self-link" href="#cookie-scope"></a></dfn> is a Content Security Policy <a data-link-type="dfn" href="https://mikewest.github.io/webappsec/specs/content-security-policy/#directive">directive</a> <a data-link-type="biblio" href="#biblio-csp">[CSP]</a> which restricts the scope in which <a data-link-type="dfn" href="https://tools.ietf.org/html/rfc6265#section-1">cookies</a> <a data-link-type="biblio" href="#biblio-rfc6265">[RFC6265]</a> can be set. The syntax is described by the following ABNF
1101-
grammar:</p>
1119+
grammar <a data-link-type="biblio" href="#biblio-rfc5234">[RFC5234]</a> (including the <a data-link-type="grammar" href="https://tools.ietf.org/html/rfc7230#section-3.2.3">RWS</a> rule from <a data-link-type="biblio" href="#biblio-rfc7230">[RFC7230]</a>:</p>
11021120
<pre>directive-name = "cookie-scope"
11031121
directive-value = <a data-link-type="grammar" href="#grammardef-scoping-rules">scoping-rules</a> *( <a data-link-type="grammar" href="https://tools.ietf.org/html/rfc7230#section-3.2.3">RWS</a> <a data-link-type="grammar" href="#grammardef-scoping-rules">scoping-rules</a> )
11041122
<dfn data-dfn-type="grammar" data-export="" id="grammardef-scoping-rules">scoping-rules<a class="self-link" href="#grammardef-scoping-rules"></a></dfn> = "<dfn data-dfn-type="grammar" data-export="" id="grammardef-host">host<a class="self-link" href="#grammardef-host"></a></dfn>" / "<dfn data-dfn-type="grammar" data-export="" id="grammardef-none">none<a class="self-link" href="#grammardef-none"></a></dfn>" / "<dfn data-dfn-type="grammar" data-export="" id="grammardef-secure">secure<a class="self-link" href="#grammardef-secure"></a></dfn>"
11051123
</pre>
1124+
<p>The directive has one of three values:</p>
1125+
<ol>
1126+
<li data-md="">
1127+
<p>"<a data-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+
<li data-md="">
1130+
<p>"<a data-link-type="grammar" href="#grammardef-none">none</a>" blocks all cookies.</p>
1131+
<li data-md="">
1132+
<p>"<a data-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 "<a data-link-type="grammar" href="#grammardef-host">host</a>" and "<a data-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 "<a data-link-type="grammar" href="#grammardef-none">none</a>" is present with any combination of the other values,
1138+
no cookies may be set.</p>
11061139
<p class="issue" id="issue-6a48c646"><a class="self-link" href="#issue-6a48c646"></a> Erik Nygren <a href="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-
<h3 class="heading settled" data-level="2.1" id="monkey-patching-rfc6264"><span class="secno">2.1. </span><span class="content">Enforcement and Monitoring</span><a class="self-link" href="#monkey-patching-rfc6264"></a></h3>
1140+
<h3 class="heading settled" data-level="2.1" id="monkey-patching-rfc6264"><span class="secno">2.1. </span><span class="content">Processing Model</span><a class="self-link" href="#monkey-patching-rfc6264"></a></h3>
11081141
<p>After step 10 of <a href="https://tools.ietf.org/html/rfc6265#section-5.3">the
11091142
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
11111144
step 11:</p>
11121145
<ol start="11">
11131146
<li> If <a href="#block-cookie">§3.1 Is cookie blocked for settings object?</a> returns "<code>Blocked</code>" when executed upon <var>cookie</var> and the <a data-link-type="dfn" href="http://www.w3.org/TR/html5/webappapis.html#incumbent-settings-object">incumbent settings object</a>,
@@ -1149,7 +1182,7 @@ <h3 class="heading settled" data-level="3.1" id="block-cookie"><span class="secn
11491182
<h3 class="heading settled" data-level="3.2" id="violates"><span class="secno">3.2. </span><span class="content"> Does <var>cookie</var> violate <var>policy</var>? </span><a class="self-link" href="#violates"></a></h3>
11501183
<ol>
11511184
<li data-md="">
1152-
<p>Let <var>scope</var> be the value of <var>policy</var>’s <a data-link-type="dfn" href="#cookie-scope">cookie-scope</a> directive.</p>
1185+
<p>Let <var>scope</var> be the result of executing <a href="#parse">§3.3 Parse string as a cookie-scope value</a> on <var>policy</var>’s <a data-link-type="dfn" href="#cookie-scope">cookie-scope</a> directive.</p>
11531186
<li data-md="">
11541187
<p>If any of the following conditions are met, return "<code>Violates</code>":</p>
11551188
<ol>
@@ -1164,10 +1197,40 @@ <h3 class="heading settled" data-level="3.2" id="violates"><span class="secno">3
11641197
<li data-md="">
11651198
<p>Return "<code>Does not violate</code>".</p>
11661199
</ol>
1200+
<h3 class="heading settled" data-level="3.3" id="parse"><span class="secno">3.3. </span><span class="content"> Parse <var>string</var> as a <code>cookie-scope</code> value </span><a class="self-link" href="#parse"></a></h3>
1201+
<p>Given a string (<var>string</var>), this algorithm returns a set of the valid <a data-link-type="dfn" href="#cookie-scope"><code>cookie-scope</code></a> values the string represents. Invalid values are
1202+
ignored:</p>
1203+
<ol>
1204+
<li data-md="">
1205+
<p><a data-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+
<li data-md="">
1207+
<p>Let <var>values</var> be an empty set.</p>
1208+
<li data-md="">
1209+
<p>For each <var>token</var> in the list generated by <a data-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+
<li data-md="">
1213+
<p>If <var>token</var> matches the grammar for <a data-link-type="grammar" href="#grammardef-scoping-rules">scoping-rules</a>, insert <var>token</var> into <var>values</var>.</p>
1214+
</ol>
1215+
<li data-md="">
1216+
<p>Return <var>values</var>.</p>
1217+
</ol>
1218+
</section>
1219+
<section>
1220+
<h2 class="heading settled" data-level="4" id="security-considerations"><span class="secno">4. </span><span class="content">Security Considerations</span><a class="self-link" href="#security-considerations"></a></h2>
1221+
<h3 class="heading settled" data-level="4.1" id="existing"><span class="secno">4.1. </span><span class="content">Existing Cookies</span><a class="self-link" href="#existing"></a></h3>
1222+
<p>Note that the mechanisms defined here do not protect against cookies that
1223+
already exist in a user’s <a data-link-type="dfn" href="https://tools.ietf.org/html/rfc6265#section-5.3">cookie store</a>. Those cookies are delivered
1224+
along with the HTTP request, before Content Security Policy can be delivered
1225+
and applied. It is possible that future work like <a data-link-type="biblio" href="#biblio-csp-pinning">[CSP-PINNING]</a> might
1226+
enable these kinds of <i lang="la">a priori</i> restrictions, but, even then,
1227+
CSP should be seen as a mitigation strategy, layered on top of filters and
1228+
sanity checks for incoming data.</p>
11671229
</section>
11681230
<section>
1169-
<h2 class="heading settled" data-level="4" id="acknowledgements"><span class="secno">4. </span><span class="content">Acknowledgements</span><a class="self-link" href="#acknowledgements"></a></h2>
1170-
<p>Mark Nottingham proposed this directive several years ago. Sorry, Mark!</p>
1231+
<h2 class="heading settled" data-level="5" id="acknowledgements"><span class="secno">5. </span><span class="content">Acknowledgements</span><a class="self-link" href="#acknowledgements"></a></h2>
1232+
<p>Mark Nottingham proposed this directive several years ago. Sorry it took so
1233+
long, Mark!</p>
11711234
</section>
11721235
</main>
11731236
<h2 class="no-ref no-num heading settled" id="conformance"><span class="content"> Conformance</span><a class="self-link" href="#conformance"></a></h2>
@@ -1211,6 +1274,8 @@ <h3 class="no-num heading settled" id="index-defined-elsewhere"><span class="con
12111274
<ul>
12121275
<li><a href="http://www.w3.org/TR/html5/webappapis.html#settings-object">environment settings object</a>
12131276
<li><a href="http://www.w3.org/TR/html5/webappapis.html#incumbent-settings-object">incumbent settings object</a>
1277+
<li><a href="http://www.w3.org/TR/html5/infrastructure.html#split-a-string-on-spaces">split a string on spaces</a>
1278+
<li><a href="http://www.w3.org/TR/html5/infrastructure.html#strip-leading-and-trailing-whitespace">strip leading and trailing whitespace</a>
12141279
</ul>
12151280
<li>
12161281
<a data-link-type="biblio" href="#biblio-rfc6265">[rfc6265]</a> defines the following terms:
@@ -1244,19 +1309,25 @@ <h3 class="no-num heading settled" id="normative"><span class="content">Normativ
12441309
<dd>Mike West; Daniel Veditz. <a href="https://w3c.github.io/webappsec/specs/content-security-policy/">Content Security Policy</a>. ED. URL: <a href="https://w3c.github.io/webappsec/specs/content-security-policy/">https://w3c.github.io/webappsec/specs/content-security-policy/</a>
12451310
<dt id="biblio-rfc6454"><a class="self-link" href="#biblio-rfc6454"></a>[RFC6454]
12461311
<dd>Adam Barth. <a href="http://www.ietf.org/rfc/rfc6454.txt">The Web Origin Concept</a>. RFC. URL: <a href="http://www.ietf.org/rfc/rfc6454.txt">http://www.ietf.org/rfc/rfc6454.txt</a>
1312+
<dt id="biblio-rfc7230"><a class="self-link" href="#biblio-rfc7230"></a>[RFC7230]
1313+
<dd>Roy T. Fielding; Julian F. Reschke. <a href="http://www.ietf.org/rfc/rfc7230.txt">HTTP/1.1 Message Syntax and Routing</a>. RFC. URL: <a href="http://www.ietf.org/rfc/rfc7230.txt">http://www.ietf.org/rfc/rfc7230.txt</a>
12471314
<dt id="biblio-url"><a class="self-link" href="#biblio-url"></a>[URL]
12481315
<dd>Anne van Kesteren. <a href="https://url.spec.whatwg.org/">URL</a>. Living Standard. URL: <a href="https://url.spec.whatwg.org/">https://url.spec.whatwg.org/</a>
12491316
<dt id="biblio-html5"><a class="self-link" href="#biblio-html5"></a>[HTML5]
12501317
<dd>Ian Hickson; et al. <a href="http://www.w3.org/TR/html5/">HTML5</a>. 28 October 2014. REC. URL: <a href="http://www.w3.org/TR/html5/">http://www.w3.org/TR/html5/</a>
12511318
<dt id="biblio-rfc2119"><a class="self-link" href="#biblio-rfc2119"></a>[RFC2119]
12521319
<dd>S. Bradner. <a href="https://tools.ietf.org/html/rfc2119">Key words for use in RFCs to Indicate Requirement Levels</a>. March 1997. Best Current Practice. URL: <a href="https://tools.ietf.org/html/rfc2119">https://tools.ietf.org/html/rfc2119</a>
1320+
<dt id="biblio-rfc5234"><a class="self-link" href="#biblio-rfc5234"></a>[RFC5234]
1321+
<dd>D. Crocker, Ed.; P. Overell. <a href="https://tools.ietf.org/html/rfc5234">Augmented BNF for Syntax Specifications: ABNF</a>. January 2008. Internet Standard. URL: <a href="https://tools.ietf.org/html/rfc5234">https://tools.ietf.org/html/rfc5234</a>
12531322
<dt id="biblio-rfc6265"><a class="self-link" href="#biblio-rfc6265"></a>[RFC6265]
12541323
<dd>A. Barth. <a href="https://tools.ietf.org/html/rfc6265">HTTP State Management Mechanism</a>. April 2011. Proposed Standard. URL: <a href="https://tools.ietf.org/html/rfc6265">https://tools.ietf.org/html/rfc6265</a>
12551324
<dt id="biblio-rfc7320"><a class="self-link" href="#biblio-rfc7320"></a>[RFC7320]
12561325
<dd>M. Nottingham. <a href="https://tools.ietf.org/html/rfc7320">URI Design and Ownership</a>. July 2014. Best Current Practice. URL: <a href="https://tools.ietf.org/html/rfc7320">https://tools.ietf.org/html/rfc7320</a>
12571326
</dl>
12581327
<h3 class="no-num heading settled" id="informative"><span class="content">Informative References</span><a class="self-link" href="#informative"></a></h3>
12591328
<dl>
1329+
<dt id="biblio-csp-pinning"><a class="self-link" href="#biblio-csp-pinning"></a>[CSP-PINNING]
1330+
<dd>Mike West. <a href="https://w3c.github.io/webappsec/specs/csp-pinning/">Content Security Policy: Pinning</a>. FPWD. URL: <a href="https://w3c.github.io/webappsec/specs/csp-pinning/">https://w3c.github.io/webappsec/specs/csp-pinning/</a>
12601331
<dt id="biblio-origin-cookies"><a class="self-link" href="#biblio-origin-cookies"></a>[ORIGIN-COOKIES]
12611332
<dd>Mike West. <a href="https://tools.ietf.org/html/draft-west-origin-cookies">Origin Cookies</a>. ID. URL: <a href="https://tools.ietf.org/html/draft-west-origin-cookies">https://tools.ietf.org/html/draft-west-origin-cookies</a>
12621333
<dt id="biblio-yummy-cookies"><a class="self-link" href="#biblio-yummy-cookies"></a>[YUMMY-COOKIES]

0 commit comments

Comments
 (0)