-
Notifications
You must be signed in to change notification settings - Fork 246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Spec: split up response validation into two stages, and fix a bug in it #1175
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,8 @@ spec: WebAssembly; urlPrefix: https://webassembly.github.io/spec/core/ | |
spec: WebAssembly-js-api; urlPrefix: https://webassembly.github.io/spec/js-api/ | ||
type: dfn | ||
text: compiling a WebAssembly module; url: #compile-a-webassembly-module | ||
type: dfn | ||
text: compiling a potential WebAssembly response; url: #compile-a-potential-webassembly-response | ||
spec: WebIDL; urlPrefix: https://webidl.spec.whatwg.org/ | ||
type: dfn | ||
text: convert a Web IDL arguments list to an ECMAScript arguments list; url: #web-idl-arguments-list-converting | ||
|
@@ -2078,23 +2080,49 @@ The <dfn http-header><code>Ad-Auction-Allowed</code></dfn> HTTP response header | |
[=structured header=] whose value must be a [=structured header/boolean=]. | ||
|
||
<div algorithm> | ||
To <dfn>validate fetching response</dfn> given a [=response=] |response|, null, failure, or a | ||
[=byte sequence=] |responseBody|, and a [=string=] |mimeType|: | ||
To <dfn>validate fetching response headers</dfn> given a [=response=] |response|: | ||
|
||
1. If |responseBody| is null or failure, return false. | ||
1. If [=header list/getting a structured field value|getting=] [:Ad-Auction-Allowed:] and | ||
"`item`" from |response|'s [=response/header list=] does not return a true value, return false. | ||
"`item`" from |response|'s [=response/header list=] does not return a true value, return false. | ||
1. If |response|'s [=response/status=] is not an [=ok status=], return false. | ||
1. Return true. | ||
</div> | ||
|
||
<div algorithm> | ||
To <dfn>validate fetching response mime and body</dfn> given a [=response=] |response|, null, | ||
failure, or a [=byte sequence=] |responseBody|, and a [=string=] |mimeType|: | ||
|
||
1. If |responseBody| is null or failure, return false. | ||
1. Let |headerMimeType| be the result of [=header list/extracting a MIME type=] from |response|'s | ||
[=response/header list=]. | ||
1. Return false if any of the following conditions hold: | ||
* |headerMimeType| is failure; | ||
* |mimeType| is "`text/javascript`" and |headerMimeType| is not a [=JavaScript MIME type=]; | ||
* |mimeType| is "`application/json`" and |headerMimeType| is not a [=JSON MIME type=]. | ||
1. Let |mimeTypeCharset| be |headerMimeType|'s [=MIME type/parameters=]["`charset`"]. | ||
1. Return false if any of the following conditions hold: | ||
* |mimeTypeCharset| does not [=map/exist=], or |mimeTypeCharset| is "utf-8", and |responseBody| | ||
is not [=UTF-8=] encoded; | ||
* |mimeTypeCharset| is "us-ascii", and not all bytes in |responseBody| are [=ASCII bytes=]. | ||
* |mimeType| is "`application/wasm`" and the result of [=header list/getting=] "`Content-Type`" | ||
from |response|'s [=response/header list=] is null or not [=byte-case-insensitive=] equal to | ||
"`application/wasm`". | ||
|
||
Note: This was intended to match the behavior of [=compiling a potential WebAssembly | ||
response=], but diverges by failing to remove leading and trailing HTTP whitespace. | ||
|
||
1. If |mimeType| is not "`application/wasm`": | ||
1. Let |mimeTypeCharset| be |headerMimeType|'s [=MIME type/parameters=]["`charset`"]. | ||
1. Return false if any of the following conditions hold: | ||
* |mimeTypeCharset| does not [=map/exist=], or |mimeTypeCharset| is "utf-8", and |responseBody| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is really weird to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Also noticed this had a logic error in that we don't actually accept things other than utf-8 or us-ascii, and fixed that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't seem done. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might help if I commit and push.... |
||
is not [=UTF-8=] encoded; | ||
* |mimeTypeCharset| is "us-ascii", and not all bytes in |responseBody| are [=ASCII bytes=]. | ||
1. Return true. | ||
</div> | ||
|
||
<div algorithm> | ||
To <dfn>validate fetching response</dfn> given a [=response=] |response|, null, failure, or a | ||
[=byte sequence=] |responseBody|, and a [=string=] |mimeType|: | ||
|
||
1. If the result of [=validating fetching response headers=] given |response| is false, then | ||
return false. | ||
1. If the result of [=validating fetching response mime and body=] given |response|, | ||
|responseBody|, |mimeType| is false, then return false. | ||
1. Return true. | ||
</div> | ||
|
||
|
@@ -2159,10 +2187,8 @@ To <dfn>fetch WebAssembly</dfn> given a [=URL=] |url|: | |
1. Let |moduleObject| be null. | ||
1. [=Fetch=] |request| with [=fetch/processResponseConsumeBody=] set to the following steps given | ||
a [=response=] |response| and null, failure, or a [=byte sequence=] |responseBody|: | ||
1. Set |moduleObject| to failure and return, if any of the following conditions hold: | ||
* |responseBody| is null or failure; | ||
* [=header list/getting a structured field value|Getting=] [:Ad-Auction-Allowed:] and "`item`" | ||
from |response|'s [=response/header list=] does not return a true value. | ||
1. If [=validate fetching response=] with |response|, |responseBody| and "`application/wasm`" | ||
returns false, set |moduleObject| to failure and return. | ||
1. Let |module| be the result of [=compiling a WebAssembly module=] |response|. | ||
1. If |module| is [=error=], set |moduleObject| to failure. | ||
1. Otherwise, set |moduleObject| to |module|. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use [=HTTP tab or space=] since that's what [=get, decode, and split=] (called by extract a mime type).
HTTP whitespace contains U+000A LF, U+000D CR, and [=HTTP tab or space=], so it's different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, the removal is motivated by https://webassembly.github.io/spec/web-api/#compile-a-potential-webassembly-response step 4 (which probably is motivated by proper parsing)
Changed to http tab or space, thanks.
I am not sure on changing our code simply because we're supposed to be super-conservative about backwards compatibility (and the change can break things by making wasm load when it failed to before), but it is a reasonable thing to consider changing in the code in my book since things that break would break would do so because they were doing something silly, not something reasonable.