From fbf2055d5ffd308b9d9364709df5aad2320497e8 Mon Sep 17 00:00:00 2001
From: Joel Howard Willis Weinberger Scripts, of course, are not the only resource type which would benefit
+ Scripts, of course, are not the only resource type which would benefit
from integrity validation. The scheme specified here applies to all HTML
elements which trigger fetches, as well as to fetches triggered from CSS
and JavaScript.Introduction
sha256-C6CB9UYIS9UJeqinPHWTHVqh/E1uhG5Twh+Y5qFQmYg=">
- Key Concepts and Terminology
and format of that resource. [[!MIMETYPE]]
The message body and the transfer encoding of a resource -are defined by RFC7230, section 3. [[!RFC7230]]
+are defined by RFC7230, section 3. [[!RFC7230]]The representation data and content encoding of a resource are defined by RFC7231, section 3. [[!RFC7231]]
@@ -690,6 +690,14 @@integrity
attributeThe integrity
IDL attribute must reflect the integrity
content attribute.
It should be noted that this syntax does not allow for content negotiation if
+the developer specifies a MIME type. A change to the syntax to allow this may be
+considered in a future version of the spec, but for now, if a developer wants to
+use content negotiation, they will have to omit an option-expression
.
integrity
attributeIt should be noted that this syntax does not allow for content negotiation if
the developer specifies a MIME type. A change to the syntax to allow this may be
considered in a future version of the spec, but for now, if a developer wants to
-use content negotiation, they will have to omit an option-expression
.
type
option-expression
.
diff --git a/specs/subresourceintegrity/spec.markdown b/specs/subresourceintegrity/spec.markdown
index 5a21cf9c..38a05e6c 100755
--- a/specs/subresourceintegrity/spec.markdown
+++ b/specs/subresourceintegrity/spec.markdown
@@ -575,7 +575,7 @@ The `integrity` IDL attribute must [reflect][] the `integrity` content attribute
It should be noted that this syntax does not allow for [content negotiation][] if
the developer specifies a MIME type. A change to the syntax to allow this may be
considered in a future version of the spec, but for now, if a developer wants to
-use content negotiation, they will have to omit an `option-expression`.
+use content negotiation, they will have to omit a `type` `option-expression`.
[content negotiation]: https://www.igvita.com/2013/05/01/deploying-webp-via-accept-content-negotiation/
From 54e31a12846eff424a018ce9d2078cfec798a888 Mon Sep 17 00:00:00 2001
From: Joel Howard Willis Weinberger HTTPS
.
[potentially secure origin]: #dfn-potentially-secure-origin
[mixedcontent]: https://www.w3.org/TR/mixed-content/#potentially-secure-origin
-The MIME type of a resource is a technical hint about the use
-and format of that resource. [[!MIMETYPE]]
-
The message body and the transfer encoding of a resource
are defined by [RFC7230, section 3][messagebody]. [[!RFC7230]]
@@ -200,11 +195,9 @@ metadata, which consists of the following pieces of information:
* cryptographic hash function ("alg")
* [digest][] ("val")
-* the resource's [MIME type][] ("type")
The hash function and digest MUST be provided in order to validate a
-resource's integrity. The MIME type SHOULD be provided, as it mitigates the
-risk of certain attack vectors.
+resource's integrity.
This metadata MUST be encoded in the same format as the `hash-source`
in [section 4.2 of the Content Security Policy Level 2 specification][csp2-section42].
@@ -217,11 +210,6 @@ digest that results. This can be encoded as follows:
sha256-qznLcsROx4GACP2dm0UCKCzCG+HiZ1guq6ZZDob/Tng=
{:.example.highlight}
-Or, if the author further wishes to specify the Content Type (`application/javascript`):
-
- type:application/javascript sha256-qznLcsROx4GACP2dm0UCKCzCG+HiZ1guq6ZZDob/Tng=
-{:.example.highlight}
-
script
element, like so:
<script src="https://code.jquery.com/jquery-1.10.2.min.js"
- integrity="type:application/javascript
- sha256-C6CB9UYIS9UJeqinPHWTHVqh/E1uhG5Twh+Y5qFQmYg=">
+ integrity="sha256-C6CB9UYIS9UJeqinPHWTHVqh/E1uhG5Twh+Y5qFQmYg=">
Scripts, of course, are not the only resource type which would benefit @@ -192,7 +191,7 @@
link
element included on her page:
<link rel="stylesheet" href="https://site53.cdn.net/style.css"
- integrity="type:text/css sha256-SDfwewFAE...wefjijfE">
+ integrity="sha256-SDfwewFAE...wefjijfE">
script
element she includes on her page:
<script src="https://analytics-r-us.com/v1.0/include.js"
- integrity="type:application/javascript
- sha256-SDfwewFAE...wefjijfE"></script>
+ integrity="sha256-SDfwewFAE...wefjijfE"></script>
HTTPS
.
- The MIME type of a resource is a technical hint about the use -and format of that resource. [[!MIMETYPE]]
-The message body and the transfer encoding of a resource are defined by RFC7230, section 3. [[!RFC7230]]
@@ -295,12 +290,10 @@The hash function and digest MUST be provided in order to validate a -resource’s integrity. The MIME type SHOULD be provided, as it mitigates the -risk of certain attack vectors.
+resource’s integrity.This metadata MUST be encoded in the same format as the hash-source
in section 4.2 of the Content Security Policy Level 2 specification.
sha256-qznLcsROx4GACP2dm0UCKCzCG+HiZ1guq6ZZDob/Tng=
- Or, if the author further wishes to specify the Content Type (application/javascript
):
type:application/javascript sha256-qznLcsROx4GACP2dm0UCKCzCG+HiZ1guq6ZZDob/Tng=
-
-
Digests may be generated using any number of utilities. OpenSSL, for example, is quite commonly available. The example in this section is the @@ -353,9 +341,8 @@
Authors may choose to specify both, for example:
<script src="hello_world.js"
- integrity="type:application/javascript
- sha256-+MO/YqmqPm/BYZwlDkir51GTc9Pt9BvmLrXcRRma8u8=
- sha512-rQw3wx1psxXzqB8TyM3nAQlK2RcluhsNwxmcqXE2YbgoDW735o8TPmIR4uWpoxUERddvFwjgRSGw7gNPCwuvJg==
+ integrity="sha256-+MO/YqmqPm/BYZwlDkir51GTc9Pt9BvmLrXcRRma8u8=
+ sha512-rQw3wx1psxXzqB8TyM3nAQlK2RcluhsNwxmcqXE2YbgoDW735o8TPmIR4uWpoxUERddvFwjgRSGw7gNPCwuvJg==
"></script>
@@ -379,15 +366,14 @@ User agents MUST provide a mechanism of determining the relative priority of
-two hash functions. That is, if a user agent implemented a function like
-getPrioritizedHashFunction(a, b) it would return the hash function
-the user agent considers the most collision-resistant.
-For example, getPrioritizedHashFunction('SHA-256', 'SHA-512')
would return
-SHA-512
.
User agents MUST provide a mechanism of determining the relative priority of two
+hash functions and return the empty string if the priority is equal. That is, if
+a user agent implemented a function like getPrioritizedHashFunction(a,
+b) it would return the hash function the user agent considers the most
+collision-resistant. For example, getPrioritizedHashFunction('SHA-256',
+'SHA-512')
would return SHA-512
and getPrioritizedHashFunction('SHA-256',
+'SHA-256')
would return the empty string.
If both algorithms are equally strong, the user agent SHOULD ensure that there -is a consistent ordering.
getPrioritizedHashFunction(currentAlgorithm, newAlgorithm)
-is newAlgorithm, set strongest to
-item.no metadata
, return true
.false
.true
. Otherwise, return false
.true
.false
.If expectedType is the empty string in #10, it would -be reasonable for the user agent to warn the page’s author about the -dangers of MIME type confusion attacks via its developer console.
+This algorithm allows the user agent to accept multiple, valid strong hash
+functions. For example, a developer might write a script
element such as:
<script src="https://foobar.com/content-changes.js"
+ integrity="sha256-C6CB9UYIS9UJeqinPHWTHVqh/E1uhG5Twh+Y5qFQmYg=
+ sha256-qznLcsROx4GACP2dm0UCKCzCG+HiZ1guq6ZZDob/Tng=">
+
+
+ which would allow the user agent to accept two different content payloads, one +of which matches the first SHA256 hash value and the other matches the second +SHA256 hash value.
User agents may allow users to modify the result of this algorithm via user preferences, bookmarklets, third-party additions to the user agent, and other @@ -603,12 +600,6 @@
pending
.Cache-Control
header whose value is “no-transform”.Accept
header value to the value
-of request’s integrity metadata’s Content Type.integrity
attributeintegrity-metadata = *WSP [ option-expression *( 1*WSP option-expression ) 1*WSP ] hash-expression *( 1*WSP hash-expression ) *WSP / *WSP
-option-expression = option-name ":" option-value
+ integrity-metadata = *WSP hash-with-options *( 1*WSP hash-with-options ) *WSP / *WSP
+hash-with-options = hash-expression *("?" option-expression)
+option-expression = option-name "=" option-value
option-name = 1*option-name-char
option-name-char = ALPHA / DIGIT / "-"
option-value = *option-value-char
@@ -685,17 +677,14 @@ The integrity
attribute
hash-expression = hash-algo "-" base64-value
- At the moment, the only option-name that is defined is type
and its
-value must be a valid MIME type.
-
The integrity
IDL attribute must reflect the integrity
content attribute.
-
- It should be noted that this syntax does not allow for content negotiation if
-the developer specifies a MIME type. A change to the syntax to allow this may be
-considered in a future version of the spec, but for now, if a developer wants to
-use content negotiation, they will have to omit a type
option-expression
.
+ option-expression
s are associated on a per hash-expression
basis and are
+applied only to the hash-expression
that immediately precedes it.
+
+ At the moment, no option-expression
s are defined. However, future versions of
+the spec make define options, such as [MIME types][].
diff --git a/specs/subresourceintegrity/spec.markdown b/specs/subresourceintegrity/spec.markdown
index 255d4aaf..f679c8cf 100755
--- a/specs/subresourceintegrity/spec.markdown
+++ b/specs/subresourceintegrity/spec.markdown
@@ -271,15 +271,14 @@ stronger hash functions as they become available.
#### Priority
-User agents MUST provide a mechanism of determining the relative priority of
-two hash functions. That is, if a user agent implemented a function like
-getPrioritizedHashFunction(a, b) it would return the hash function
-the user agent considers the most collision-resistant.
-For example, `getPrioritizedHashFunction('SHA-256', 'SHA-512')` would return
-`SHA-512`.
-
-If both algorithms are equally strong, the user agent SHOULD ensure that there
-is a consistent ordering.
+User agents MUST provide a mechanism of determining the relative priority of two
+hash functions and return the empty string if the priority is equal. That is, if
+a user agent implemented a function like getPrioritizedHashFunction(a,
+b) it would return the hash function the user agent considers the most
+collision-resistant. For example, `getPrioritizedHashFunction('SHA-256',
+'SHA-512')` would return `SHA-512` and `getPrioritizedHashFunction('SHA-256',
+'SHA-256')` would return the empty string.
+
@@ -397,19 +396,22 @@ the user agent.
#### Get the strongest metadata from set.
-1. Let strongest be the empty string.
+1. Let result be the empty set and strongest be the empty
+ string.
2. For each item in set:
- 1. If strongest is the empty string, set strongest
- to item, skip to the next
- item.
+ 1. If result is the empty set, add item to
+ result and set strongest to item, skip
+ to the next item.
2. Let currentAlgorithm be the alg component of
strongest.
3. Let newAlgorithm be the alg component of
item.
4. If the result of [`getPrioritizedHashFunction(currentAlgorithm, newAlgorithm)`][getPrioritizedHashFunction]
- is newAlgorithm, set strongest to
- item.
-3. Return strongest.
+ is the empty string, add item to result. If the
+ result is newAlgorithm, set strongest to
+ item, set result to the empty set, and add
+ item to result.
+3. Return result.
[getPrioritizedHashFunction]: #dfn-getprioritizedhashfunction-a-b
@@ -424,14 +426,29 @@ the user agent.
4. If parsedMetadata is `no metadata`, return `true`.
5. Let metadata be the result of [getting the strongest
metadata from parsedMetadata][get-the-strongest].
-6. Let algorithm be the alg component of
- metadata.
-7. Let expectedValue be the val component of
- metadata.
-8. Let actualValue be the result of [applying
- algorithm to resource][apply-algorithm].
-9. If actualValue is a case-sensitive match for
- expectedValue, return `true`. Otherwise, return `false`.
+6. For each item in metadata:
+ 1. Let algorithm be the alg component of
+ metadata.
+ 2. Let expectedValue be the val component of
+ metadata.
+ 3. Let actualValue be the result of [applying
+ algorithm to resource][apply-algorithm].
+ 4. If actualValue is a case-sensitive match for
+ expectedValue, return `true`.
+7. Return `false`.
+
+This algorithm allows the user agent to accept multiple, valid strong hash
+functions. For example, a developer might write a `script` element such as:
+
+