Skip to content
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

Editorial: Add guidelines for external specs about CORS, cross-origin isolation and TAO #1806

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions fetch.bs
Original file line number Diff line number Diff line change
Expand Up @@ -9062,6 +9062,107 @@ done only by navigations). The <a>fetch controller</a> is also used to
<a for=request>redirect mode</a> set to "<code>manual</code>".


<h3 id=fetch-elsewhere-security>Same-origin policy when using fetch</h3>

<p>The Fetch standard enforces some of the mechanisms that constitute the Same Origin Policy (SOP),
which is a critical aspect of web security. Specifically, Fetch imposes SOP restrictions on network
access.

<p>In a nutshell, when a user accesses a certain origin using their browser or other user agent,
they don't expect that the user agent implicitly grants that <a for=/>origin</a> full access to
their network, which could, for example, be an intranet, despite the user agent itself having that
access.
Comment on lines +9071 to +9074
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This paragraph may be too focused on users. What are specs using Fetch supposed to do to help with the SOP? It seems like their job is to ensure that resources are fetched with one of the request modes, which will ensure that one origin can't get illegitimate access to resources protected by credentials or network identity.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was actually important for me to be focused on users! But point taken.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


<p>In addition, the user agent may include footprint that identifies the user to the origin,
explicitly using cookies or client certificates, or implicitly using, for example, the user-agent's
IP address.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this connected to the same-origin policy? A site that wants to leak this kind of information can always embed an <iframe>.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imagine any domain had read access to corp-intranet.com/about-my-computer.json and it gave you all kinds of information about yourself, identifying you by your IP address.


<p>To keep this information from leaking, SOP restricts requests that come from the visited
<a for=/>origin</a> to only target that same-origin, while allowing a few mechanisms for an origin
noamr marked this conversation as resolved.
Show resolved Hide resolved
to access cross-origin data safely.

<h4 id=fetch-elsewhere-cors>Cross-origin resource sharing (CORS)</h4>

<p>The main way to access cross-origin data is via the <a>cors protocol</a>, described in detail in
this standard. CORS (Cross Origin Resource Sharing) is built on the principle that origins that want
Comment on lines +9086 to +9087
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mention that this is selected by setting the request mode to "cors".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

to access data from other origins need to identify themselves, and get explicit approval from the
server to access that data, thus not relying on any implict trust given to the user agent or to the
machine the user agent is installed on.

<p>This is done by sending the `<a http-header><code>Origin</code></a>` header with CORS-enabled
requests, and expecting a matching `<a http-header><code>Access-Control-Allow-Origin</code></a>`
response header in return.

<p>The <a>CORS-preflight fetch</a> mechanism extends this further, by sending that identification
handshake as a separate request, prior to sending the payload of the request itself.

<p>For any new spec invoking <a for=/>fetch</a> to access cross-origin rersources, CORS should be
the only option. This has been implemented in multiple newer standards such as web fonts and module
scripts.

<h4 id=fetch-elsewhere-no-cors>No-CORS requests</h4>

<p>Embedding cross-origin resources, without the ability to read them, existed prior to CORS.
Cross-origin images, scripts, stylesheets & media are embeddable in a <a for=/>document</a> without
the embedding <a for=/>origin</a> identifying themselves and receive explicit confirmation.

<p>To maintain backwards compatibility, this form of fetching is still supported. Instead of
restricting the network access, the embedder is restricted in what they are allowed to do with the
<a for=/>response</a>. They can embed it in their document and present it to the user, but this has
to be done in a way that's opaque to the embedding origin. Only the user should have access to the
resource, not the embedder.
noamr marked this conversation as resolved.
Show resolved Hide resolved

<p>This mechanism of fetching should not be used in new specs. However, specs should be written with
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mention that it's the default request mode, and so every new spec should set a request mode explicitly.

the notion that no-CORS resources exists, and the new spec should not grant origins the ability to
read their contents.
domfarolino marked this conversation as resolved.
Show resolved Hide resolved

<h4 id=fetch-elsewhere-cross-origin-isolation>CORP & Cross-origin isolation</h4>

<p>Due to the leaky nature of no-CORS requests, resources can further protect themselves by
providing a `<a http-header><code>Cross-Origin-Resource-Policy</code></a>` header (CORP). By
Comment on lines +9128 to +9129
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What spec language should consuming specs use to opt into or cooperate with this protection?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already mentioned in detail in one of the previous sections about populating the request object, I'll refer back to that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

supplying the appropriate CORP header, a resource can opt out from being embedded by a different
site or origin. For example, this can be used to protect an image's <a>natural dimensions</a> from
being read by an embedded.
noamr marked this conversation as resolved.
Show resolved Hide resolved

<p>This protection is especially important when exposing powerful features to the web platform, that
gain enough access to the underlying platform to read cross-origin resources using attacks like
Spectre. This category of features, e.g. <code>SharedArrayBuffer</code> or high-resolution
noamr marked this conversation as resolved.
Show resolved Hide resolved
timestamps, cannot be used together with the default policy that allows cross-origin content to be
embedded.

<p>Instead, the embedder must use
<a data-lt="cross-origin isolated capability">cross-origin isolation</a>, using the
`<a http-header><code>Cross-Origin-Embedder-Policy</code></a>` header to restrict embedding of
cross-origin resources only to resources that explicitly allow this.

<p>Note that CORP and cross-origin isolation are not designed to be a "lighter version of CORS".
Their purpose is to restrict embedding of existing resources that are normally embeddable without
CORS, in order to enable safe usage of powerful platform features.

<p>Other specifications should consider requiring CORP if they expose a powerful platform feature,
regardless of whether they themselves invoke <a for=/>fetch</a>.

<h4 id=fetch-elsewhere-TAO>Accessing timing information (TAO)</h4>

<p>Beside the protections for the resource's data itself, the Fetch standard enforces restrictions
on accessing timing information associated with the <a for=/>fetch</a>. This timing information
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, what do specs need to write in order to mark some information as "timing information"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added something

includes multiple milestones in the fetch process, such as receiving the first redirect or beginning
the DNS lookup, as described in the <cite>Resource Timing</cite> spec. [[RESOURCE-TIMING]]

<p>This information, like any other information, is protected by the Same-Origin Policy, and
is available by default for same-origin resources only. A server delivering a cross-origin resource
can relax this restriction by including the `<code>Timing-Allow-Origin</code>` header in the
response.

<p>The `<code>Timing-Allow-Origin</code>` (TAO) header is orthogonal to CORS, as CORS allows sharing
information about the resource, while TAO allows sharing information about the particular fetch,
and in particular only timing information.

<p>Note that the TAO status does not persist with a <a for=/>response</a> when it enters the cache
or forwarded using a Service Worker. TAO is valid for a single <a for=/>Fetch</a>, and only enables
sharing information about the fetch that is clearly timing related.


<h2 id=acknowledgments class=no-num>Acknowledgments</h2>

<p>Thanks to
Expand Down