Skip to content

Commit c9d8983

Browse files
authored
Add the cross-origin isolated primitive
A top-level navigation response with Cross-Origin-Opener-Policy set to same-origin and Cross-Origin-Embedder-Policy set to require-corp will create a cross-origin isolated browsing context group. And all agent clusters therein will be cross-origin isolated as well (shared and service workers can still not be, as they sit on the side). This change also: * Gates SharedArrayBuffer exposure behind that primitive for web compatibility reasons. * Gates SharedArrayBuffer sharing behind that primitive. * Exposes it through self.crossOriginIsolated. * Makes document.domain return before it mutates the origin. * Makes agent clusters keyed on origin. Tests: * web-platform-tests/wpt#17719 * web-platform-tests/wpt#17760 * web-platform-tests/wpt#17761 * web-platform-tests/wpt#17802 * web-platform-tests/wpt#17909 * web-platform-tests/wpt#18543 * web-platform-tests/wpt#20116 * web-platform-tests/wpt#22358 Closes #4732. Closes #5122. Closes #5444. Follow-up: #5435 (and #5362).
1 parent e5a5991 commit c9d8983

File tree

1 file changed

+83
-34
lines changed

1 file changed

+83
-34
lines changed

source

Lines changed: 83 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8002,13 +8002,24 @@ interface <dfn>DOMStringList</dfn> {
80028002
<p>If ! <span>IsSharedArrayBuffer</span>(<var>value</var>) is true, then:
80038003

80048004
<ol>
8005+
<li><p>Let <var>agentCluster</var> be the <span>surrounding agent</span>'s
8006+
<span>agent cluster</span>.</p></li>
8007+
8008+
<li>
8009+
<p>If <var>agentCluster</var>'s <span>cross-origin isolated</span> is false, then throw a
8010+
<span>"<code>DataCloneError</code>"</span> <code>DOMException</code>.</p>
8011+
8012+
<p class="note">This check is only needed when serializing (and not when deserializing) as
8013+
<span>cross-origin isolated</span> cannot change over time and a
8014+
<code>SharedArrayBuffer</code> cannot leave an <span>agent cluster</span>.</p>
8015+
</li>
8016+
80058017
<li><p>If <var>forStorage</var> is true, then throw a
80068018
<span>"<code>DataCloneError</code>"</span> <code>DOMException</code>.</p></li>
80078019

80088020
<li><p>Set <var>serialized</var> to { [[Type]]: "SharedArrayBuffer", [[ArrayBufferData]]:
80098021
<var>value</var>.[[ArrayBufferData]], [[ArrayBufferByteLength]]: <var>size</var>,
8010-
[[AgentCluster]]: the <span>current Realm Record</span>'s corresponding <span>agent
8011-
cluster</span> }.</p></li>
8022+
[[AgentCluster]]: <var>agentCluster</var> }.</p></li>
80128023
</ol>
80138024
</li>
80148025

@@ -77229,10 +77240,6 @@ console.assert(iframeWindow.frameElement === null);
7722977240
<p>A <span>browsing context group</span> has a <dfn data-x="bcg cross-origin
7723077241
isolated">cross-origin isolated</dfn> boolean. It is initially false.</p>
7723177242

77232-
<p class="XXX">The impact of <span data-x="bcg cross-origin isolated">cross-origin
77233-
isolated</span> is under discussion in <a href="https://github.com/whatwg/html/pull/4734">issue
77234-
#4734</a>.</p>
77235-
7723677243
<p>To <dfn data-x="creating a new browsing context group">create a new browsing context
7723777244
group</dfn>, run these steps:</p>
7723877245

@@ -79650,6 +79657,9 @@ interface <dfn>BarProp</dfn> {
7965079657
a registrable domain suffix of and is not equal to</span> <var>effectiveDomain</var>, then throw
7965179658
a <span>"<code>SecurityError</code>"</span> <code>DOMException</code>.</p></li>
7965279659

79660+
<li><p>If the <span>surrounding agent</span>'s <span>agent cluster</span>'s <span>cross-origin
79661+
isolated</span> is true, then return.</p></li>
79662+
7965379663
<li><p>Set this <code>Document</code> object's <span>origin</span>'s <span
7965479664
data-x="concept-origin-domain">domain</span> to the result of <span data-x="host
7965579665
parser">parsing</span> the given value.</p></li>
@@ -86819,6 +86829,10 @@ interface <dfn>ApplicationCache</dfn> : <span>EventTarget</span> {
8681986829
<p>Contains various <code>Window</code> objects which can potentially reach each other, either
8682086830
directly or by using <code data-x="dom-document-domain">document.domain</code>.</p>
8682186831

86832+
<p>If the encompassing <span>agent cluster</span>'s <span>cross-origin isolated</span> is true,
86833+
then all the <code>Window</code> objects will be <span>same origin</span>, can reach each other
86834+
directly, and <code data-x="dom-document-domain">document.domain</code> will no-op.</p>
86835+
8682286836
<p class="note">Two <code>Window</code> objects that are <span>same origin</span> can be in
8682386837
different <span data-x="similar-origin window agent">similar-origin window agents</span>, for
8682486838
instance if they are each in their own <span>browsing context group</span>.</p>
@@ -86897,51 +86911,43 @@ interface <dfn>ApplicationCache</dfn> : <span>EventTarget</span> {
8689786911
ensure that web developers see interoperable behavior with regard to shared memory, even in the
8689886912
face of varying and changing user agent process models.</p>
8689986913

86914+
<p>An <span>agent cluster</span> has an associated <dfn>cross-origin isolated</dfn> (a boolean),
86915+
which is initially false.</p>
86916+
8690086917
<div w-nodev>
8690186918

8690286919
<hr>
8690386920

8690486921
<p>The following defines the allocation of the <span data-x="agent cluster">agent clusters</span>
8690586922
of <span data-x="similar-origin window agent">similar-origin window agents</span>.</p>
8690686923

86907-
<p>An <dfn>agent cluster key</dfn> is a <span>site</span>.</p>
86908-
86909-
<p class="XXX"><a href="https://github.com/whatwg/html/pull/4734">whatwg/html #4734</a> is
86910-
expected to widen <span>agent cluster key</span> (but not <span>site</span>) to encompass all
86911-
<span data-x="concept-origin-tuple">tuple origins</span>.</p>
86912-
86913-
<p>To <dfn data-x="obtain-agent-cluster-key">obtain an agent cluster key</dfn>, given an origin
86914-
<var>origin</var>, return the result of <span data-x="obtain a site">obtaining a site</span> with
86915-
<var>origin</var>.</p>
86924+
<p>An <dfn>agent cluster key</dfn> is a <span>site</span> or <span
86925+
data-x="concept-origin-tuple">tuple origin</span> whose <span
86926+
data-x="concept-origin-host">host</span>'s <span>registrable domain</span> is non-null. I.e., an
86927+
<span>agent cluster key</span> can be a <span>scheme-and-registrable-domain</span> or any
86928+
<span>origin</span>.</p>
8691686929

8691786930
<p>To <dfn data-x="obtain-similar-origin-window-agent">obtain a similar-origin window agent</dfn>,
8691886931
given an <span>origin</span> <var>origin</var> and <span>browsing context group</span>
8691986932
<var>group</var>, run these steps:</p>
8692086933

8692186934
<ol>
86922-
<li><p>Let <var>clusterKey</var> be the result of <span
86923-
data-x="obtain-agent-cluster-key" data-export="">obtaining an agent cluster key</span> given
86924-
<var>origin</var>.</p></li>
86925-
86926-
<li><p>Let <var>agentCluster</var> be the result of <span
86927-
data-x="obtain-browsing-agent-cluster">obtaining a browsing context agent cluster</span> with
86928-
<var>group</var> and <var>clusterKey</var>.</p></li>
86929-
86930-
<li><p>Return the single <span>similar-origin window agent</span> contained in
86931-
<var>agentCluster</var>.</p></li>
86932-
</ol>
86935+
<li><p>Let <var>clusterKey</var> be the result of <span data-x="obtain a site">obtaining a
86936+
site</span> with <var>origin</var>.</p></li>
8693386937

86934-
<p>To <dfn data-x="obtain-browsing-agent-cluster">obtain a browsing context agent cluster</dfn>,
86935-
given a <span>browsing context group</span> <var>group</var> and <span>agent cluster key</span>
86936-
<var>key</var>, run these steps:</p>
86938+
<li><p>If <var>group</var>'s <span data-x="bcg cross-origin isolated">cross-origin
86939+
isolated</span> is true, then set <var>clusterKey</var> to <var>origin</var>.</p></li>
8693786940

86938-
<ol>
8693986941
<li>
8694086942
<p>If <var>group</var>'s <span>agent cluster map</span>[<var>key</var>] <span data-x="map
86941-
exists">does not exist, then:</span></p>
86943+
exists">does not exist</span>, then:</p>
86944+
8694286945
<ol>
8694386946
<li><p>Let <var>agentCluster</var> be a new <span>agent cluster</span>.</p></li>
8694486947

86948+
<li><p>Set <var>agentCluster</var>'s <span>cross-origin isolated</span> to <var>group</var>'s
86949+
<span data-x="bcg cross-origin isolated">cross-origin isolated</span>.</p></li>
86950+
8694586951
<li><p>Add the result of <span data-x="create an agent">creating an agent</span>, given false,
8694686952
to <var>agentCluster</var>.</p></li>
8694786953

@@ -86950,7 +86956,8 @@ interface <dfn>ApplicationCache</dfn> : <span>EventTarget</span> {
8695086956
</ol>
8695186957
</li>
8695286958

86953-
<li><p>Return <var>group</var>'s <span>agent cluster map</span>[<var>key</var>].</p></li>
86959+
<li><p>Return the single <span>similar-origin window agent</span> contained in <var>group</var>'s
86960+
<span>agent cluster map</span>[<var>key</var>].</p></li>
8695486961
</ol>
8695586962

8695686963
<p class="note">This means that there is only one <span>similar-origin window agent</span> per
@@ -87304,6 +87311,26 @@ interface <dfn>ApplicationCache</dfn> : <span>EventTarget</span> {
8730487311
is not yet defined in the JavaScript specification; see <a
8730587312
href="https://github.com/tc39/ecma262/issues/1357">tc39/ecma262#1357</a>.</span></p></li>
8730687313

87314+
<li>
87315+
<p>If <var>agent</var>'s <span>agent cluster</span>'s <span>cross-origin isolated</span> is
87316+
false, then:</p>
87317+
87318+
<ol>
87319+
<li><p>Let <var>global</var> be <var>realm</var>'s <span data-x="concept-realm-global">global
87320+
object</span>.</p></li>
87321+
87322+
<li><p>Let <var>status</var> be ! <var>global</var>.[[Delete]]("<code
87323+
data-x="">SharedArrayBuffer</code>").</p></li>
87324+
87325+
<li><p>Assert: <var>status</var> is true.</p></li>
87326+
</ol>
87327+
87328+
<p class="note">This is done for compatibility with web content and there is some hope that this
87329+
can be removed in the future. Web developers can still get at the constructor through
87330+
<code class="js" data-x="">new WebAssembly.Memory({ shared:true, initial:0, maximum:0
87331+
}).buffer.constructor</code>.</p>
87332+
</li>
87333+
8730787334
<li><p>Return <var>realm execution context</var>.</p></li>
8730887335
</ol>
8730987336

@@ -92109,6 +92136,7 @@ interface mixin <dfn>DocumentAndElementEventHandlers</dfn> {
9210992136
interface mixin <dfn>WindowOrWorkerGlobalScope</dfn> {
9211092137
[Replaceable] readonly attribute USVString <span data-x="dom-origin">origin</span>;
9211192138
readonly attribute boolean <span data-x="dom-isSecureContext">isSecureContext</span>;
92139+
readonly attribute boolean <span data-x="dom-crossOriginIsolated">crossOriginIsolated</span>;
9211292140

9211392141
// base64 utility methods
9211492142
DOMString <span data-x="dom-btoa">btoa</span>(DOMString data);
@@ -92132,13 +92160,19 @@ interface mixin <dfn>WindowOrWorkerGlobalScope</dfn> {
9213292160

9213392161
<dl class="domintro">
9213492162
<dt>self . <code subdfn data-x="dom-isSecureContext">isSecureContext</code></dt>
92135-
9213692163
<dd><p>Returns whether or not this global object represents a <span>secure context</span>. <ref
9213792164
spec=SECURE-CONTEXTS></p></dd>
9213892165

9213992166
<dt>self . <code subdfn data-x="dom-origin">origin</code></dt>
92140-
9214192167
<dd><p>Returns the global object's <span>origin</span>, serialized as string.</p></dd>
92168+
92169+
<dt>self . <code subdfn data-x="dom-crossOriginIsolated">crossOriginIsolated</code></dt>
92170+
<dd><p>Returns whether the <span>surrounding agent</span>'s <span>agent cluster</span> is
92171+
<span>cross-origin isolated</span>. This depends on the `<code
92172+
data-x="">Cross-Origin-Opener-Policy</code>` and `<code
92173+
data-x="">Cross-Origin-Embedder-Policy</code>` HTTP response headers and determines whether
92174+
<code>SharedArrayBuffer</code> can be used with <code data-x="">postMessage()</code>
92175+
APIs.</p></dd>
9214292176
</dl>
9214392177

9214492178
<div class="example">
@@ -92169,6 +92203,10 @@ document.body.appendChild(frame)</code></pre>
9216992203
data-x="concept-settings-object-origin">origin</span>, <span data-x="serialization of an
9217092204
origin">serialized</span>.</p>
9217192205

92206+
<p>The <dfn data-x="dom-crossOriginIsolated"><code>crossOriginIsolated</code></dfn> getter steps
92207+
are to return the <span>surrounding agent</span>'s <span>agent cluster</span>'s <span>cross-origin
92208+
isolated</span>.</p>
92209+
9217292210
</div>
9217392211

9217492212

@@ -99061,6 +99099,17 @@ interface <dfn>SharedWorkerGlobalScope</dfn> : <span>WorkerGlobalScope</span> {
9906199099
<span data-x="obtain an embedder policy">obtaining an embedder policy</span> from
9906299100
<var>response</var>.</p></li>
9906399101

99102+
<li>
99103+
<p>If <var>worker global scope</var>'s <span
99104+
data-x="concept-WorkerGlobalScope-embedder-policy">embedder policy</span> is "<code
99105+
data-x="coep-require-corp">require-corp</code>" and <var>is shared</var> is true, then set
99106+
<var>agent</var>'s <span>agent cluster</span>'s <span>cross-origin isolated</span> to
99107+
true.</p>
99108+
99109+
<p class="XXX">This really ought to be set when the agent cluster is created, which requires a
99110+
redesign of this section.</p>
99111+
</li>
99112+
9906499113
<li><p>If the result of <span data-x="check a global object's embedder policy">checking a
9906599114
global object's embedder policy</span> with <var>worker global scope</var>, <var>owner</var>,
9906699115
and <var>response</var> is false, then set <var>response</var> to a <span>network

0 commit comments

Comments
 (0)