Skip to content

Commit 955b60e

Browse files
morlovichMaks Orlovich
andauthored
Spec: split up response validation into two stages, and fix a bug in it (WICG#1175)
* Spec: split up response validation into two stages, and fix a bug in it We will need to do checking in two stages for script bodies to get the proper cross-site seller signals behavior. While at it, make sure we actually check that the response is a 2xx; we are not supposed to be trying to use error pages. Also make the WASM path go through this, too, so it gets this check as well. * Document WASM behavior. * Elaborate * Fix link, more precise whitespace. * Fix the exists thing + encoding check --------- Co-authored-by: Maks Orlovich <[email protected]>
1 parent 75867d6 commit 955b60e

File tree

1 file changed

+43
-13
lines changed

1 file changed

+43
-13
lines changed

spec.bs

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ spec: WebAssembly; urlPrefix: https://webassembly.github.io/spec/core/
6666
spec: WebAssembly-js-api; urlPrefix: https://webassembly.github.io/spec/js-api/
6767
type: dfn
6868
text: compiling a WebAssembly module; url: #compile-a-webassembly-module
69+
spec: WebAssembly-web-api; urlPrefix: https://webassembly.github.io/spec/web-api/
70+
type: dfn
71+
text: compiling a potential WebAssembly response; url: #compile-a-potential-webassembly-response
6972
spec: WebIDL; urlPrefix: https://webidl.spec.whatwg.org/
7073
type: dfn
7174
text: convert a Web IDL arguments list to an ECMAScript arguments list; url: #web-idl-arguments-list-converting
@@ -2054,23 +2057,52 @@ The <dfn http-header><code>Ad-Auction-Allowed</code></dfn> HTTP response header
20542057
[=structured header=] whose value must be a [=structured header/boolean=].
20552058

20562059
<div algorithm>
2057-
To <dfn>validate fetching response</dfn> given a [=response=] |response|, null, failure, or a
2058-
[=byte sequence=] |responseBody|, and a [=string=] |mimeType|:
2060+
To <dfn>validate fetching response headers</dfn> given a [=response=] |response|:
20592061

2060-
1. If |responseBody| is null or failure, return false.
20612062
1. If [=header list/getting a structured field value|getting=] [:Ad-Auction-Allowed:] and
2062-
"`item`" from |response|'s [=response/header list=] does not return a true value, return false.
2063+
"`item`" from |response|'s [=response/header list=] does not return a true value, return false.
2064+
1. If |response|'s [=response/status=] is not an [=ok status=], return false.
2065+
1. Return true.
2066+
</div>
2067+
2068+
<div algorithm>
2069+
To <dfn>validate fetching response mime and body</dfn> given a [=response=] |response|, null,
2070+
failure, or a [=byte sequence=] |responseBody|, and a [=string=] |mimeType|:
2071+
2072+
1. If |responseBody| is null or failure, return false.
20632073
1. Let |headerMimeType| be the result of [=header list/extracting a MIME type=] from |response|'s
20642074
[=response/header list=].
20652075
1. Return false if any of the following conditions hold:
20662076
* |headerMimeType| is failure;
20672077
* |mimeType| is "`text/javascript`" and |headerMimeType| is not a [=JavaScript MIME type=];
20682078
* |mimeType| is "`application/json`" and |headerMimeType| is not a [=JSON MIME type=].
2069-
1. Let |mimeTypeCharset| be |headerMimeType|'s [=MIME type/parameters=]["`charset`"].
2070-
1. Return false if any of the following conditions hold:
2071-
* |mimeTypeCharset| does not [=map/exist=], or |mimeTypeCharset| is "utf-8", and |responseBody|
2072-
is not [=UTF-8=] encoded;
2073-
* |mimeTypeCharset| is "us-ascii", and not all bytes in |responseBody| are [=ASCII bytes=].
2079+
* |mimeType| is "`application/wasm`" and the result of [=header list/getting=] "`Content-Type`"
2080+
from |response|'s [=response/header list=] is null or not [=byte-case-insensitive=] equal to
2081+
"`application/wasm`".
2082+
2083+
Note: This was intended to match the behavior of [=compiling a potential WebAssembly
2084+
response=], but diverges by failing to remove leading and trailing [=HTTP tab or space
2085+
bytes=].
2086+
2087+
1. If |mimeType| is not "`application/wasm`":
2088+
1. Let |mimeTypeCharset| be "utf-8".
2089+
1. If |headerMimeType|'s [=MIME type/parameters=]["`charset`"] exists, set |mimeTypeCharset|
2090+
to |headerMimeType|'s [=MIME type/parameters=]["`charset`"].
2091+
1. Return true if any of the following conditions hold:
2092+
* |mimeTypeCharset| is "utf-8", and |responseBody| is [=UTF-8=] encoded;
2093+
* |mimeTypeCharset| is "us-ascii", and all bytes in |responseBody| are [=ASCII bytes=].
2094+
1. Return false.
2095+
1. Return true.
2096+
</div>
2097+
2098+
<div algorithm>
2099+
To <dfn>validate fetching response</dfn> given a [=response=] |response|, null, failure, or a
2100+
[=byte sequence=] |responseBody|, and a [=string=] |mimeType|:
2101+
2102+
1. If the result of [=validating fetching response headers=] given |response| is false, then
2103+
return false.
2104+
1. If the result of [=validating fetching response mime and body=] given |response|,
2105+
|responseBody|, |mimeType| is false, then return false.
20742106
1. Return true.
20752107
</div>
20762108

@@ -2135,10 +2167,8 @@ To <dfn>fetch WebAssembly</dfn> given a [=URL=] |url|:
21352167
1. Let |moduleObject| be null.
21362168
1. [=Fetch=] |request| with [=fetch/processResponseConsumeBody=] set to the following steps given
21372169
a [=response=] |response| and null, failure, or a [=byte sequence=] |responseBody|:
2138-
1. Set |moduleObject| to failure and return, if any of the following conditions hold:
2139-
* |responseBody| is null or failure;
2140-
* [=header list/getting a structured field value|Getting=] [:Ad-Auction-Allowed:] and "`item`"
2141-
from |response|'s [=response/header list=] does not return a true value.
2170+
1. If [=validate fetching response=] with |response|, |responseBody| and "`application/wasm`"
2171+
returns false, set |moduleObject| to failure and return.
21422172
1. Let |module| be the result of [=compiling a WebAssembly module=] |response|.
21432173
1. If |module| is [=error=], set |moduleObject| to failure.
21442174
1. Otherwise, set |moduleObject| to |module|.

0 commit comments

Comments
 (0)