Skip to content

Commit de73e7a

Browse files
author
Francois Marier
committed
Merge pull request #488 from mozfreddyb/sha256-to-sha384
Rewrite instance of SHA256 to SHA384, see issue #477
2 parents 7e8a523 + 479a946 commit de73e7a

File tree

2 files changed

+38
-38
lines changed

2 files changed

+38
-38
lines changed

specs/subresourceintegrity/index.html

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ <h2 id="introduction">Introduction</h2>
157157
and the <code>fetch()</code> API with an <code>integrity</code> attribute that contains a cryptographic hash
158158
of the representation of the resource the author expects to load. For instance,
159159
an author may wish to load some framework from a shared server rather than hosting it
160-
on their own origin. Specifying that the <em>expected</em> SHA-256 hash of
160+
on their own origin. Specifying that the <em>expected</em> SHA-384 hash of
161161
<code>https://example.com/example-framework.js</code>
162-
is <code>C6CB9UYIS9UJeqinPHWTHVqh/E1uhG5Twh+Y5qFQmYg=</code> means
162+
is <code>Li9vy3DqF8tnTXuiaAJuML3ky+er10rcgNR/VqsVpcw+ThHmYcwiB1pbOxEbzJr7</code> means
163163
that the user agent can verify that the data it loads from that URL matches
164164
that expected hash before executing the JavaScript it contains. This
165165
integrity verification significantly reduces the risk that an attacker can
@@ -169,11 +169,11 @@ <h2 id="introduction">Introduction</h2>
169169
<code>script</code> element, like so:</p>
170170

171171
<pre><code>&lt;script src="https://example.com/example-framework.js"
172-
integrity="sha256-C6CB9UYIS9UJeqinPHWTHVqh/E1uhG5Twh+Y5qFQmYg="
172+
integrity="sha384-Li9vy3DqF8tnTXuiaAJuML3ky+er10rcgNR/VqsVpcw+ThHmYcwiB1pbOxEbzJr7"
173173
crossorigin="anonymous"&gt;&lt;/script&gt;
174174
</code></pre>
175175

176-
<p>Scripts, of course, are not the only response type which would benefit
176+
<p class="example">Scripts, of course, are not the only response type which would benefit
177177
from integrity validation. The scheme specified here also applies to <code>link</code>
178178
and future versions of the specification are likely to expand this coverage.</p>
179179

@@ -214,7 +214,7 @@ <h4 id="resource-integrity">Resource Integrity</h4>
214214
<a href="#dfn-integrity-metadata">integrity metadata</a> is added to the <code>link</code> element included on the page:</p>
215215

216216
<pre class="example"><code>&lt;link rel="stylesheet" href="https://site53.example.net/style.css"
217-
integrity="sha256-vjnUh7+rXHH2lg/5vDY8032ftNVCIEC21vL6szrVw9M="
217+
integrity="sha384-+/M6kredJcxdsqkczBUjMLvqyHb1K/JThDXWsBVxMEeZHEaMKEOEct339VItX1zB"
218218
crossorigin="anonymous"&gt;
219219
</code></pre>
220220
</li>
@@ -225,7 +225,7 @@ <h4 id="resource-integrity">Resource Integrity</h4>
225225
the script, and adds it to the <code>script</code> element:</p>
226226

227227
<pre class="example"><code>&lt;script src="https://analytics-r-us.example.com/v1.0/include.js"
228-
integrity="sha256-Rj/9XDU7F6pNSX8yBddiCIIS+XKDTtdq0//No0MH0AE="
228+
integrity="sha384-MBO5IDfYaE6c6Aao94oZrIOiC6CGiSN2n4QUbHNPhzk5Xhm0djZLQqTpL0HzTUxk"
229229
crossorigin="anonymous"&gt;&lt;/script&gt;
230230
</code></pre>
231231
</li>
@@ -271,7 +271,7 @@ <h3 id="key-concepts-and-terminology">Key Concepts and Terminology</h3>
271271
is an origin whose scheme component is <code>HTTPS</code>.</p>
272272

273273
<p>The <dfn>message body</dfn> and the <dfn>transfer encoding</dfn> of a resource
274-
are defined by <a href="http://tools.ietf.org/html/rfc7230#section-3">RFC7230, section 3</a>. [[!RFC7230]] </p>
274+
are defined by <a href="http://tools.ietf.org/html/rfc7230#section-3">RFC7230, section 3</a>. [[!RFC7230]]</p>
275275

276276
<p>The <dfn>representation data</dfn> and <dfn>content encoding</dfn> of a resource
277277
are defined by <a href="http://tools.ietf.org/html/rfc7231#section-3">RFC7231, section 3</a>. [[!RFC7231]]</p>
@@ -331,19 +331,19 @@ <h3 id="integrity-metadata">Integrity metadata</h3>
331331
in <a href="http://www.w3.org/TR/CSP11/#source-list-syntax">section 4.2 of the Content Security Policy Level 2 specification</a>.</p>
332332

333333
<p>For example, given a script resource containing only the string "alert('Hello, world.');",
334-
an author might choose <a href="#dfn-sha-2">SHA-256</a> as a hash function.
335-
<code>qznLcsROx4GACP2dm0UCKCzCG+HiZ1guq6ZZDob/Tng=</code> is the base64-encoded
334+
an author might choose [SHA-384<a href="#dfn-sha-2">sha2</a> as a hash function.
335+
<code>H8BRh8j48O9oYatfu5AZzq6A9RINhZO5H16dQZngK7T62em8MUt1FLm52t+eX6xO</code> is the base64-encoded
336336
digest that results. This can be encoded as follows:</p>
337337

338-
<pre class="example"><code>sha256-qznLcsROx4GACP2dm0UCKCzCG+HiZ1guq6ZZDob/Tng=
338+
<pre class="example"><code>sha384-H8BRh8j48O9oYatfu5AZzq6A9RINhZO5H16dQZngK7T62em8MUt1FLm52t+eX6xO
339339
</code></pre>
340340

341341
<div class="note">
342342
<p>Digests may be generated using any number of utilities. <a href="http://www.openssl.org/">OpenSSL</a>, for
343343
example, is quite commonly available. The example in this section is the
344344
result of the following command line:</p>
345345

346-
<pre><code>echo -n "alert('Hello, world.');" | openssl dgst -sha256 -binary | openssl enc -base64 -A
346+
<pre><code>echo -n "alert('Hello, world.');" | openssl dgst -sha384 -binary | openssl enc -base64 -A
347347
</code></pre>
348348

349349
</div>
@@ -366,14 +366,14 @@ <h4 id="agility">Agility</h4>
366366
For example, the resource described in the previous section may be described
367367
by either of the following hash expressions:</p>
368368

369-
<pre><code>sha256-qznLcsROx4GACP2dm0UCKCzCG+HiZ1guq6ZZDob/Tng=
369+
<pre><code>sha384-dOTZf16X8p34q2/kYyEFm0jh89uTjikhnzjeLeF0FHsEaYKb1A1cv+Lyv4Hk8vHd
370370
sha512-Q2bFTOhEALkN8hOms2FKTDLy7eugP2zFZ1T8LCvX42Fp3WoNr3bjZSAHeOsHrbV1Fu9/A0EzCinRE7Af1ofPrw==
371371
</code></pre>
372372

373373
<p>Authors may choose to specify both, for example:</p>
374374

375375
<pre><code>&lt;script src="hello_world.js"
376-
integrity="sha256-qznLcsROx4GACP2dm0UCKCzCG+HiZ1guq6ZZDob/Tng=
376+
integrity="sha384-dOTZf16X8p34q2/kYyEFm0jh89uTjikhnzjeLeF0FHsEaYKb1A1cv+Lyv4Hk8vHd
377377
sha512-Q2bFTOhEALkN8hOms2FKTDLy7eugP2zFZ1T8LCvX42Fp3WoNr3bjZSAHeOsHrbV1Fu9/A0EzCinRE7Af1ofPrw=="
378378
crossorigin="anonymous"&gt;&lt;/script&gt;
379379
</code></pre>
@@ -446,7 +446,7 @@ <h4 id="is-response-eligible-for-integrity-validation">Is <var>response</var> el
446446
checks if they are same-origin or are the result of explicit access granted to
447447
the loading origin via CORS. [[!CORS]]</p>
448448

449-
<p class="note">As noted in <a href="http://tools.ietf.org/html/rfc6454#section-4">RFC6454, section 4</a>, some user agents use
449+
<p class="note">As noted in <a class="note" href="http://tools.ietf.org/html/rfc6454#section-4">RFC6454, section 4</a>, some user agents use
450450
globally unique identifiers for each file URI. This means that
451451
resources accessed over a <code>file</code> scheme URL are unlikely to be
452452
eligible for integrity checks.</p>
@@ -563,16 +563,16 @@ <h4 id="does-response-match-metadatalist">Does <var>response</var> match <var>me
563563
functions. For example, a developer might write a <code>script</code> element such as:</p>
564564

565565
<pre><code>&lt;script src="https://example.com/example-framework.js"
566-
integrity="sha256-C6CB9UYIS9UJeqinPHWTHVqh/E1uhG5Twh+Y5qFQmYg=
567-
sha256-qznLcsROx4GACP2dm0UCKCzCG+HiZ1guq6ZZDob/Tng="
566+
integrity="sha384-Li9vy3DqF8tnTXuiaAJuML3ky+er10rcgNR/VqsVpcw+ThHmYcwiB1pbOxEbzJr7
567+
sha384-+/M6kredJcxdsqkczBUjMLvqyHb1K/JThDXWsBVxMEeZHEaMKEOEct339VItX1zB"
568568
crossorigin="anonymous"&gt;&lt;/script&gt;
569569
</code></pre>
570570

571571
<p>which would allow the user agent to accept two different content payloads, one
572-
of which matches the first SHA256 hash value and the other matches the second
573-
SHA256 hash value.</p>
572+
of which matches the first SHA384 hash value and the other matches the second
573+
SHA384 hash value.</p>
574574

575-
<p class="note">User agents may allow users to modify the result of this algorithm via user
575+
<p class="example note">User agents may allow users to modify the result of this algorithm via user
576576
preferences, bookmarklets, third-party additions to the user agent, and other
577577
such mechanisms. For example, redirects generated by an extension like
578578
<a href="https://www.eff.org/https-everywhere">HTTPSEverywhere</a> could load and execute
@@ -754,7 +754,7 @@ <h5 id="elements">Elements</h5>
754754
<section>
755755
<h6 id="the-link-element-for-stylesheets">The <code>link</code> element for stylesheets</h6>
756756

757-
<p>Whenever a user agent attempts to <a href="http://www.w3.org/TR/html5/document-metadata.html#concept-link-obtain">obtain a resource</a> pointed to by a
757+
<p>Whenever a user agent attempts to <a start="4" href="http://www.w3.org/TR/html5/document-metadata.html#concept-link-obtain">obtain a resource</a> pointed to by a
758758
<code>link</code> element that has a <code>rel</code> attribute with the keyword of <code>stylesheet</code>,
759759
modify step 4 to read:</p>
760760

@@ -770,7 +770,7 @@ <h6 id="the-link-element-for-stylesheets">The <code>link</code> element for styl
770770
<section>
771771
<h6 id="the-script-element">The <code>script</code> element</h6>
772772

773-
<p>Replace step 14.1 of HTML5’s <a href="http://www.w3.org/TR/html5/scripting-1.html#prepare-a-script">“prepare a script” algorithm</a> with:</p>
773+
<p>Replace step 14.1 of HTML5’s <a start="6" href="http://www.w3.org/TR/html5/scripting-1.html#prepare-a-script">“prepare a script” algorithm</a> with:</p>
774774

775775
<ol>
776776
<li>Let <var>src</var> be the value of the element’s <code>src</code> attribute and
@@ -834,7 +834,7 @@ <h3 id="hash-collision-attacks">Hash collision attacks</h3>
834834
<p>Digests are only as strong as the hash function used to generate them. User
835835
agents SHOULD refuse to support known-weak hashing functions like MD5 or SHA-1,
836836
and SHOULD restrict supported hashing functions to those known to be
837-
collision-resistant. At the time of writing, SHA-256 is a good baseline.
837+
collision-resistant. At the time of writing, SHA-384 is a good baseline.
838838
Moreover, user agents SHOULD re-evaluate their supported hash functions
839839
on a regular basis, and deprecate support for those functions shown to be
840840
insecure.</p>

specs/subresourceintegrity/spec.markdown

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ This document specifies such a validation scheme, extending two HTML elements
3333
with an `integrity` attribute that contains a cryptographic hash
3434
of the representation of the resource the author expects to load. For instance,
3535
an author may wish to load some framework from a shared server rather than hosting it
36-
on their own origin. Specifying that the _expected_ SHA-256 hash of
36+
on their own origin. Specifying that the _expected_ SHA-384 hash of
3737
`https://example.com/example-framework.js`
38-
is `C6CB9UYIS9UJeqinPHWTHVqh/E1uhG5Twh+Y5qFQmYg=` means
38+
is `Li9vy3DqF8tnTXuiaAJuML3ky+er10rcgNR/VqsVpcw+ThHmYcwiB1pbOxEbzJr7` means
3939
that the user agent can verify that the data it loads from that URL matches
4040
that expected hash before executing the JavaScript it contains. This
4141
integrity verification significantly reduces the risk that an attacker can
@@ -45,7 +45,7 @@ This example can be communicated to a user agent by adding the hash to a
4545
`script` element, like so:
4646

4747
<script src="https://example.com/example-framework.js"
48-
integrity="sha256-C6CB9UYIS9UJeqinPHWTHVqh/E1uhG5Twh+Y5qFQmYg="
48+
integrity="sha384-Li9vy3DqF8tnTXuiaAJuML3ky+er10rcgNR/VqsVpcw+ThHmYcwiB1pbOxEbzJr7"
4949
crossorigin="anonymous"></script>
5050

5151
{:.example}
@@ -86,7 +86,7 @@ and future versions of the specification are likely to expand this coverage.
8686
[integrity metadata][] is added to the `link` element included on the page:
8787

8888
<link rel="stylesheet" href="https://site53.example.net/style.css"
89-
integrity="sha256-vjnUh7+rXHH2lg/5vDY8032ftNVCIEC21vL6szrVw9M="
89+
integrity="sha384-+/M6kredJcxdsqkczBUjMLvqyHb1K/JThDXWsBVxMEeZHEaMKEOEct339VItX1zB"
9090
crossorigin="anonymous">
9191
{:.example}
9292

@@ -96,7 +96,7 @@ and future versions of the specification are likely to expand this coverage.
9696
the script, and adds it to the `script` element:
9797

9898
<script src="https://analytics-r-us.example.com/v1.0/include.js"
99-
integrity="sha256-Rj/9XDU7F6pNSX8yBddiCIIS+XKDTtdq0//No0MH0AE="
99+
integrity="sha384-MBO5IDfYaE6c6Aao94oZrIOiC6CGiSN2n4QUbHNPhzk5Xhm0djZLQqTpL0HzTUxk"
100100
crossorigin="anonymous"></script>
101101
{:.example}
102102

@@ -210,19 +210,19 @@ This metadata MUST be encoded in the same format as the `hash-source` (without t
210210
in [section 4.2 of the Content Security Policy Level 2 specification][csp2-section42].
211211

212212
For example, given a script resource containing only the string \"alert(\'Hello, world.\');\",
213-
an author might choose [SHA-256][sha2] as a hash function.
214-
`qznLcsROx4GACP2dm0UCKCzCG+HiZ1guq6ZZDob/Tng=` is the base64-encoded
213+
an author might choose [SHA-384][sha2] as a hash function.
214+
`H8BRh8j48O9oYatfu5AZzq6A9RINhZO5H16dQZngK7T62em8MUt1FLm52t+eX6xO` is the base64-encoded
215215
digest that results. This can be encoded as follows:
216216

217-
sha256-qznLcsROx4GACP2dm0UCKCzCG+HiZ1guq6ZZDob/Tng=
217+
sha384-H8BRh8j48O9oYatfu5AZzq6A9RINhZO5H16dQZngK7T62em8MUt1FLm52t+eX6xO
218218
{:.example}
219219

220220
<div class="note">
221221
Digests may be generated using any number of utilities. [OpenSSL][], for
222222
example, is quite commonly available. The example in this section is the
223223
result of the following command line:
224224

225-
echo -n "alert('Hello, world.');" | openssl dgst -sha256 -binary | openssl enc -base64 -A
225+
echo -n "alert('Hello, world.');" | openssl dgst -sha384 -binary | openssl enc -base64 -A
226226

227227
[request]: https://fetch.spec.whatwg.org/#concept-request-integrity-metadata
228228
[csp2-section42]: http://www.w3.org/TR/CSP2/#source-list-syntax
@@ -249,13 +249,13 @@ resource in order to provide agility in the face of future cryptographic discove
249249
For example, the resource described in the previous section may be described
250250
by either of the following hash expressions:
251251

252-
sha256-qznLcsROx4GACP2dm0UCKCzCG+HiZ1guq6ZZDob/Tng=
252+
sha384-dOTZf16X8p34q2/kYyEFm0jh89uTjikhnzjeLeF0FHsEaYKb1A1cv+Lyv4Hk8vHd
253253
sha512-Q2bFTOhEALkN8hOms2FKTDLy7eugP2zFZ1T8LCvX42Fp3WoNr3bjZSAHeOsHrbV1Fu9/A0EzCinRE7Af1ofPrw==
254254

255255
Authors may choose to specify both, for example:
256256

257257
<script src="hello_world.js"
258-
integrity="sha256-qznLcsROx4GACP2dm0UCKCzCG+HiZ1guq6ZZDob/Tng=
258+
integrity="sha384-dOTZf16X8p34q2/kYyEFm0jh89uTjikhnzjeLeF0FHsEaYKb1A1cv+Lyv4Hk8vHd
259259
sha512-Q2bFTOhEALkN8hOms2FKTDLy7eugP2zFZ1T8LCvX42Fp3WoNr3bjZSAHeOsHrbV1Fu9/A0EzCinRE7Af1ofPrw=="
260260
crossorigin="anonymous"></script>
261261

@@ -442,13 +442,13 @@ This algorithm allows the user agent to accept multiple, valid strong hash
442442
functions. For example, a developer might write a `script` element such as:
443443

444444
<script src="https://example.com/example-framework.js"
445-
integrity="sha256-C6CB9UYIS9UJeqinPHWTHVqh/E1uhG5Twh+Y5qFQmYg=
446-
sha256-qznLcsROx4GACP2dm0UCKCzCG+HiZ1guq6ZZDob/Tng="
445+
integrity="sha384-Li9vy3DqF8tnTXuiaAJuML3ky+er10rcgNR/VqsVpcw+ThHmYcwiB1pbOxEbzJr7
446+
sha384-+/M6kredJcxdsqkczBUjMLvqyHb1K/JThDXWsBVxMEeZHEaMKEOEct339VItX1zB"
447447
crossorigin="anonymous"></script>
448448

449449
which would allow the user agent to accept two different content payloads, one
450-
of which matches the first SHA256 hash value and the other matches the second
451-
SHA256 hash value.
450+
of which matches the first SHA384 hash value and the other matches the second
451+
SHA384 hash value.
452452

453453
{:.example}
454454

@@ -648,7 +648,7 @@ specification.
648648
Digests are only as strong as the hash function used to generate them. User
649649
agents SHOULD refuse to support known-weak hashing functions like MD5 or SHA-1,
650650
and SHOULD restrict supported hashing functions to those known to be
651-
collision-resistant. At the time of writing, SHA-256 is a good baseline.
651+
collision-resistant. At the time of writing, SHA-384 is a good baseline.
652652
Moreover, user agents SHOULD re-evaluate their supported hash functions
653653
on a regular basis, and deprecate support for those functions shown to be
654654
insecure.

0 commit comments

Comments
 (0)