Skip to content

Commit 50ebcb4

Browse files
committed
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.
1 parent 60b4b4b commit 50ebcb4

File tree

1 file changed

+78
-33
lines changed

1 file changed

+78
-33
lines changed

source

+78-33
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+
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,44 @@ 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+
86917+
8690086918
<div w-nodev>
8690186919

8690286920
<hr>
8690386921

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

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>
86925+
<p>An <dfn>agent cluster key</dfn> is a <span>site</span> or <span
86926+
data-x="concept-origin-tuple">tuple origin</span> whose <span
86927+
data-x="concept-origin-host">host</span>'s <span>registrable domain</span> is non-null. I.e., an
86928+
<span>agent cluster key</span> can be any <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>
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>
8692986937

86930-
<li><p>Return the single <span>similar-origin window agent</span> contained in
86931-
<var>agentCluster</var>.</p></li>
86932-
</ol>
86933-
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
8694186943
exists">does not exist, then:</span></p>
86944+
8694286945
<ol>
8694386946
<li><p>Let <var>agentCluster</var> be a new <span>agent cluster</span>.</p></li>
8694486947

86948+
<li><p>If <var>group</var>'s <span data-x="bcg cross-origin isolated">cross-origin
86949+
isolated</span> is true, then set <var>agentCluster</var>'s <span>cross-origin isolated</span>
86950+
to true.</p></li>
86951+
8694586952
<li><p>Add the result of <span data-x="create an agent">creating an agent</span>, given false,
8694686953
to <var>agentCluster</var>.</p></li>
8694786954

@@ -86950,7 +86957,8 @@ interface <dfn>ApplicationCache</dfn> : <span>EventTarget</span> {
8695086957
</ol>
8695186958
</li>
8695286959

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

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

87315+
<li><p>Let <var>crossOriginIsolated</var> be <var>agent</var>'s <span>agent cluster</span>'s
87316+
<span>cross-origin isolated</span>.</p></li>
87317+
87318+
<li>
87319+
<p>If <var>crossOriginIsolated</var> is false, then remove the own property with name "<code
87320+
data-x="">SharedArrayBuffer</code>" from <var>realm</var>'s <span>global object</span>.</p>
87321+
87322+
<p class="note">This is done for compatibility with web content and there is some hope that this
87323+
can be removed in the future. Web developers can still get at the constructor through
87324+
<code data-x="">new WebAssembly.Memory({ shared:true, initial:0, maximum:0
87325+
}).buffer.constructor</code>.</p>
87326+
</li>
87327+
8730787328
<li><p>Return <var>realm execution context</var>.</p></li>
8730887329
</ol>
8730987330

@@ -92109,6 +92130,7 @@ interface mixin <dfn>DocumentAndElementEventHandlers</dfn> {
9210992130
interface mixin <dfn>WindowOrWorkerGlobalScope</dfn> {
9211092131
[Replaceable] readonly attribute USVString <span data-x="dom-origin">origin</span>;
9211192132
readonly attribute boolean <span data-x="dom-isSecureContext">isSecureContext</span>;
92133+
readonly attribute boolean <span data-x="dom-crossOriginIsolated">crossOriginIsolated</span>;
9211292134

9211392135
// base64 utility methods
9211492136
DOMString <span data-x="dom-btoa">btoa</span>(DOMString data);
@@ -92132,13 +92154,21 @@ interface mixin <dfn>WindowOrWorkerGlobalScope</dfn> {
9213292154

9213392155
<dl class="domintro">
9213492156
<dt>self . <code subdfn data-x="dom-isSecureContext">isSecureContext</code></dt>
92135-
9213692157
<dd><p>Returns whether or not this global object represents a <span>secure context</span>. <ref
9213792158
spec=SECURE-CONTEXTS></p></dd>
9213892159

9213992160
<dt>self . <code subdfn data-x="dom-origin">origin</code></dt>
92140-
9214192161
<dd><p>Returns the global object's <span>origin</span>, serialized as string.</p></dd>
92162+
92163+
<dt>self . <code subdfn data-x="dom-crossOriginIsolated">crossOriginIsolated</code></dt>
92164+
<dd>
92165+
<p>Returns the <span>surrounding agent</span>'s <span>agent cluster</span>'s <span>cross-origin
92166+
isolated</span>.</p>
92167+
92168+
<p>(This value depends on the <code data-x="">Cross-Origin-Opener-Policy</code> and <code
92169+
data-x="">Cross-Origin-Embedder-Policy</code> HTTP response headers and determines whether
92170+
<code>SharedArrayBuffer</code> can be used with <code data-x="">postMessage()</code> APIs.)</p>
92171+
</dd>
9214292172
</dl>
9214392173

9214492174
<div class="example">
@@ -92169,6 +92199,10 @@ document.body.appendChild(frame)</code></pre>
9216992199
data-x="concept-settings-object-origin">origin</span>, <span data-x="serialization of an
9217092200
origin">serialized</span>.</p>
9217192201

92202+
<p>The <dfn data-x="dom-crossOriginIsolated"><code>crossOriginIsolated</code></dfn> attribute's
92203+
getter must return the <span>surrounding agent</span>'s <span>agent cluster</span>'s
92204+
<span>cross-origin isolated</span>.</p>
92205+
9217292206
</div>
9217392207

9217492208

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

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

0 commit comments

Comments
 (0)