Skip to content

Commit b56692a

Browse files
authored
Describe filtered responses better
Fixes #1509. Follow-ups: #1511 & #1512.
1 parent 6291752 commit b56692a

File tree

1 file changed

+52
-16
lines changed

1 file changed

+52
-16
lines changed

fetch.bs

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2304,18 +2304,29 @@ known as an <dfn export id=concept-aborted-network-error>aborted network error</
23042304

23052305
<hr>
23062306

2307-
<p>A <dfn export id=concept-filtered-response>filtered response</dfn> is a limited view on a
2308-
<a for=/>response</a> that is not a
2309-
<a>network error</a>. This
2310-
<a for=/>response</a> is referred to as the
2311-
<a>filtered response</a>'s associated
2312-
<dfn export id=concept-internal-response for="filtered response">internal response</dfn>.
2313-
2314-
<p class="note no-backref">The <a for=/>fetch</a> algorithm returns such a view to ensure APIs do
2315-
not accidentally leak information. If the information needs to be exposed for legacy reasons, e.g.,
2316-
to feed image data to a decoder, the associated <a for="filtered response">internal response</a> can
2317-
be used, which is only "accessible" to internal specification algorithms and is never a
2318-
<a>filtered response</a> itself.
2307+
<p>A <dfn export id=concept-filtered-response>filtered response</dfn> is a <a for=/>response</a>
2308+
that offers a limited view on an associated <a for=/>response</a>. This associated
2309+
<a for=/>response</a> can be accessed through <a>filtered response</a>'s
2310+
<dfn export id=concept-internal-response for="filtered response">internal response</dfn> (a
2311+
<a for=/>response</a> that is neither a <a for=/>network error</a> nor a
2312+
<a for=/>filtered response</a>).
2313+
2314+
<p>Unless stated otherwise a <a for=/>filtered response</a>'s associated concepts (such as its
2315+
<a for=response>body</a>) refer to the associated concepts of its
2316+
<a for="filtered response">internal response</a>. (The exceptions to this are listed below as part
2317+
of defining the concrete types of <a for=/>filtered responses</a>.)
2318+
2319+
<div class=note>
2320+
<p>The <a for=/>fetch</a> algorithm by way of <a for=fetch><i>processResponse</i></a> and
2321+
equivalent parameters exposes <a for=/>filtered responses</a> to callers to ensure they do not
2322+
accidentally leak information. If the information needs to be revealed for legacy reasons, e.g., to
2323+
feed image data to a decoder, the associated <a for="filtered response">internal response</a> can
2324+
be used by specification algorithms.
2325+
2326+
<p>New specifications ought not to build further on <a>opaque filtered responses</a> or
2327+
<a>opaque-redirect filtered responses</a>. Those are legacy constructs and cannot always be
2328+
adequately protected given contemporary computer architecture.
2329+
</div>
23192330

23202331
<p>A <dfn export id=concept-filtered-response-basic>basic filtered response</dfn> is a
23212332
<a>filtered response</a> whose
@@ -2357,7 +2368,7 @@ is a <a>filtered response</a> whose
23572368
<a for=response>header list</a> is empty, and
23582369
<a for=response>body</a> is null.
23592370

2360-
<div class="note no-backref">
2371+
<div class=note>
23612372
<p>Exposing the <a for=response>URL list</a> for
23622373
<a lt="opaque-redirect filtered response">opaque-redirect filtered responses</a> is harmless since
23632374
no redirects are followed.
@@ -2371,6 +2382,30 @@ is a <a>filtered response</a> whose
23712382
<a attribute for=Response lt=ok><code>response.ok</code></a>, will return rather useless results.
23722383
</div>
23732384

2385+
<div class=example id=example-filtered-responses>
2386+
<p>The <a for=response>type</a> of a <a for=/>response</a> is exposed to script through the
2387+
{{Response/type}} getter:
2388+
2389+
<pre><code class=lang-javascript>
2390+
console.log(new Response().type); // "default"
2391+
2392+
console.log((await fetch("/")).type); // "basic"
2393+
2394+
console.log((await fetch("https://api.example/status")).type); // "cors"
2395+
2396+
console.log((await fetch("https://crossorigin.example/image", { mode: "no-cors" })).type); // "opaque"
2397+
2398+
console.log((await fetch("/surprise-me", { redirect: "manual" })).type); // "opaqueredirect"
2399+
</code></pre>
2400+
<!-- "error" is exposed through Response.error().type, but seems like a design mistake as
2401+
network errors are otherwise always exposed through a TypeError exception. -->
2402+
2403+
<p>(This assumes that the various resources exist, <code>https://api.example/status</code> has the
2404+
appropriate CORS headers, and <code>/surprise-me</code> uses a <a>redirect status</a>.)
2405+
</div>
2406+
2407+
<hr>
2408+
23742409
<p>To <dfn export for=response id=concept-response-clone>clone</dfn> a
23752410
<a for=/>response</a> <var>response</var>, run these steps:
23762411

@@ -2390,6 +2425,8 @@ is a <a>filtered response</a> whose
23902425
<li><p>Return <var>newResponse</var>.
23912426
</ol>
23922427

2428+
<hr>
2429+
23932430
<p>A <dfn id=concept-fresh-response>fresh response</dfn> is a <a for=/>response</a> whose
23942431
<a href=https://datatracker.ietf.org/doc/html/rfc7234#section-4.2.3>current age</a> is within its
23952432
<a href=https://datatracker.ietf.org/doc/html/rfc7234#section-4.2.1>freshness lifetime</a>.
@@ -4403,9 +4440,8 @@ steps:
44034440
<li><p>Let <var>processBodyError</var> be this step: run <a>fetch response handover</a> given
44044441
<var>fetchParams</var> and a <a>network error</a>.
44054442

4406-
<li><p>If <var>request</var>'s <a for=request>response tainting</a> is "<code>opaque</code>" or
4407-
<var>response</var>'s <a for=response>body</a> is null, then run <var>processBodyError</var> and
4408-
abort these steps.
4443+
<li><p>If <var>response</var>'s <a for=response>body</a> is null, then run
4444+
<var>processBodyError</var> and abort these steps.
44094445

44104446
<li>
44114447
<p>Let <var>processBody</var> given <var>bytes</var> be these steps:

0 commit comments

Comments
 (0)