Skip to content

Commit c0c121f

Browse files
camillelamyclamy
authored and
clamy
committed
Add cross-origin opener policy
Tests: https://github.com/web-platform-tests/wpt/tree/master/html/cross-origin-opener-policy Closes: whatwg#4580 Fix formatting issues Fix some more formatting issues Addressed code review comments Addressed comments Addressed comments
1 parent 249553b commit c0c121f

File tree

1 file changed

+291
-4
lines changed

1 file changed

+291
-4
lines changed

source

Lines changed: 291 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2654,6 +2654,9 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
26542654
<li><dfn data-x="concept-request-history-navigation-flag" data-x-href="https://fetch.spec.whatwg.org/#concept-request-history-navigation-flag">history-navigation flag</dfn></li>
26552655
</ul>
26562656
</li>
2657+
<li><dfn data-x="concept-header-list-get"
2658+
data-x-href="https://fetch.spec.whatwg.org/#concept-header-list-get">Getting a header</dfn>
2659+
from a header list.</li>
26572660
</ul>
26582661

26592662
<p>The following terms are defined in <cite>Referrer Policy</cite>: <ref
@@ -4021,6 +4024,20 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
40214024
<li><dfn data-x-href="https://w3c.github.io/requestidlecallback/#start-an-idle-period-algorithm">start an idle period algorithm</dfn></li>
40224025
</ul>
40234026
</dd>
4027+
4028+
<dt>Cross-Origin Embedder Policy</dt>
4029+
4030+
<dd>
4031+
<p>The following feature is defined in <cite>Cross-Origin Embedder Policy</cite>: <ref
4032+
spec=COEP></p>
4033+
4034+
<ul class="brief">
4035+
<li><dfn data-x="cross-origin-embedder-policy"
4036+
data-x-href="https://wicg.github.io/cross-origin-embedder-policy/#embedder-policy">embedder
4037+
policy</dfn></li>
4038+
</ul>
4039+
</dd>
4040+
40244041
</dl>
40254042

40264043
<hr>
@@ -8986,6 +9003,11 @@ partial interface <dfn id="document" data-lt="">Document</dfn> {
89869003
data-x="concept-document-module-map">module map</dfn>, which is a <span>module map</span>,
89879004
initially empty.</p>
89889005

9006+
<p>The <code>Document</code> has a <dfn data-dfn-for="Document"
9007+
data-x="concept-document-coop">cross-origin opener policy</dfn>, which is a
9008+
<span data-x="cross-origin-opener-policy">cross-origin opener policy</span>,
9009+
initially "<code data-x="">unsafe-none</code>".</p>
9010+
89899011
<h4>The <code>DocumentOrShadowRoot</code> interface</h4>
89909012

89919013
<p><cite>DOM</cite> defines the <code data-x="DOM
@@ -76448,13 +76470,25 @@ dictionary <dfn>DragEventInit</dfn> : <span>MouseEventInit</span> {
7644876470
settings object">setting up a window environment settings object</span> given <var>realm
7644976471
execution context</var> and <var>topLevelOrigin</var>.</p></li>
7645076472

76473+
<li><p>Let <var>COOP</var> be a <span
76474+
data-x="cross-origin-opener-policy">cross-origin-opener-policy</span> with value "<code
76475+
data-x="">unsafe-none</code>".</p></li>
76476+
76477+
<li><p>If <var>creator</var> is non-null, let <var>creatorOrigin</var> be its <span>origin</span>
76478+
and let <var>creatorTopLevelOrigin</var> be its <span>top-level origin</span>. If
76479+
<var>creatorOrigin</var> is <span>same origin</span> with <var>creatorTopLevelOrigin</var>, then
76480+
set <var>COOP</var> to <var>creator</var>'s <span>top-level browsing context</span>'s
76481+
<code>Document</code>'s <span data-x="concept-document-coop">cross-origin opener
76482+
policy</span>.</p></li>
76483+
7645176484
<li><p>Let <var>document</var> be a new <code>Document</code>, marked as an <span data-x="HTML
7645276485
documents">HTML document</span> in <span>quirks mode</span>, whose <span
7645376486
data-x="concept-document-content-type">content type</span> is "<code data-x="">text/html</code>",
7645476487
<span>origin</span> is <var>origin</var>, <span>active sandboxing flag set</span> is
7645576488
<var>sandboxFlags</var>, <span data-x="concept-document-feature-policy">feature policy</span> is
76456-
<var>feature policy</var>, and which is both <span>ready for post-load tasks</span> and
76457-
<span>completely loaded</span> immediately.</p></li>
76489+
<var>feature policy</var>, <span data-x="concept-document-coop">cross-origin opener policy</span>
76490+
is <var>COOP</var>, and which is both <span>ready for post-load tasks</span> and <span>completely
76491+
loaded</span> immediately.</p></li>
7645876492

7645976493
<li><p>Ensure that <var>document</var> has a single child <code>html</code> node, which itself
7646076494
has two empty child nodes: a <code>head</code> element, and a <code>body</code> element.</p></li>
@@ -77002,6 +77036,13 @@ console.assert(iframeWindow.frameElement === null);
7700277036
keys</span> to <span data-x="agent cluster">agent clusters</span>). User agents are responsible
7700377037
for collecting agent clusters when it is deemed that nothing can access them anymore.</p>
7700477038

77039+
<p>A <span>browsing context group</span> has a <dfn data-x="bcg cross-origin
77040+
isolated">cross-origin isolated</dfn> boolean. It is initially false.</p>
77041+
77042+
<p class="XXX">The impact of <span data-x="bcg cross-origin isolated">cross-origin
77043+
isolated</span> is under discussion in <a href="https://github.com/whatwg/html/pull/4734">issue
77044+
#4734</a>.</p>
77045+
7700577046
<p>To <dfn data-x="creating a new browsing context group">create a new browsing context
7700677047
group</dfn>, run these steps:</p>
7700777048

@@ -77300,6 +77341,27 @@ console.assert(iframeWindow.frameElement === null);
7730077341

7730177342
<dd>
7730277343
<ol>
77344+
<li>
77345+
<p>If <var>current</var>'s <span>top-level browsing context</span>'s <span>active
77346+
document</span>'s <span data-x="cross-origin-opener-policy">cross-origin opener
77347+
policy</span> is "<code data-x="">same-origin</code>" or "<code
77348+
data-x="">same-origin-plus-COEP</code>", then:</p>
77349+
77350+
<ol>
77351+
<li><p>Let <var>currentDocument</var> be <var>current</var>'s
77352+
<span>active document</span>.</p> </li>
77353+
77354+
<li>
77355+
<p>If <var>currentDocument</var>'s <span>origin</span> is not <span>same origin</span>
77356+
with <var>current</var>'s <span>top-level origin</span>, then set <var>noopener</var> to
77357+
true and <var>name</var> to "<code data-x="">_blank</code>".</p>
77358+
77359+
<p class="note">In the presence of COOP, nested documents cross-origin with their
77360+
top-level browsing context always set /noopener/.</p>
77361+
</li>
77362+
</ol>
77363+
</li>
77364+
7730377365
<li><p>Set <var>new</var> to true.</p></li>
7730477366

7730577367
<li id="noopener"><p>If <var>noopener</var> is true, then set <var>chosen</var> to the result
@@ -79736,6 +79798,166 @@ interface <dfn>BarProp</dfn> {
7973679798

7973779799

7973879800

79801+
<h3>Cross-origin opener policy</h3>
79802+
79803+
<p>A <dfn data-x="cross-origin-opener-policy">cross-origin opener policy</dfn> restricts the set
79804+
of <span data-x="browsing context">browsing contexts</span> which can live together in a single
79805+
<span>browsing context group</span>. It has one of the following values, defaulting to "<code
79806+
data-x="">unsafe-none</code>" unless otherwise specified:</p>
79807+
79808+
<dl>
79809+
<li>
79810+
<p>"<code data-x="">same-origin-plus-COEP</code>"</p>
79811+
79812+
<p class="note">"<code data-x="">same-origin-plus-COEP</code>" cannot be directly set via the
79813+
`<code data-x="http-cross-origin-opener-policy">Cross-Origin-Opener-Policy</code>` header, but
79814+
results from a combination of setting both <code data-x="">Cross-Origin-Opener-Policy:
79815+
same-origin</code> and <code data-x="">Cross-Origin-Embedder-Policy: require-corp</code>
79816+
together.</p>
79817+
</li>
79818+
79819+
<li><p>"<code data-x="">same-origin</code>"</p></li>
79820+
79821+
<li><p>"<code data-x="">same-origin-allow-popups</code>"</p></li>
79822+
79823+
<li><p>"<code data-x="">unsafe-none</code>"</p></li>
79824+
79825+
<li>
79826+
</dl>
79827+
79828+
<p>To <dfn data-x="obtain-coop">obtain a cross-origin opener policy</dfn> from a <span
79829+
data-x="concept-response">response</span> <var>response</var> and an <span>environment</span>
79830+
<var>environment</var>:</p>
79831+
79832+
<ol>
79833+
<li><p>Let <var>securityState</var> be the result of executing <span>Is environment
79834+
settings object a secure context?</span> on <var>environment</var>.</p></li>
79835+
79836+
<li><p>If <var>securityState</var> is "<code data-x="">Not Secure</code>", then return "<code
79837+
data-x="">unsafe-none</code>".</p> </li>
79838+
79839+
<li><p>Let <var>value</var> be the result of <span data-x="concept-header-list-get">getting
79840+
</span> `<code data-x="http-cross-origin-opener-policy">Cross-Origin-Opener-Policy</code>` from
79841+
<var>response</var>'s <span data-x="concept-response-header-list">header list</span>.</p></li>
79842+
79843+
<li><p>If <var>value</var> is null, then return "<code data-x="">unsafe-none</code>".</p></li>
79844+
79845+
<li><p>Let <var>decodedValue</var> be the <span data-x="isomorphic decode">isomorphic
79846+
decoding</span> of <var>value</var></p></li>
79847+
79848+
<li><p>If <var>decodedValue</var> is not "<code data-x="">same-origin</code>" or "<code
79849+
data-x="">same-origin-allow-popups</code>", then return "<code
79850+
data-x="">unsafe-none</code>".</p></li>
79851+
79852+
<li><p>If <var>decodedValue</var> is "<code data-x="">same-origin</code>", then:</p>
79853+
79854+
<ol>
79855+
<li><p>Let <var>COEP</var> be the result of obtaining a <span
79856+
data-x="cross-origin-embedder-policy">cross-origin embedder policy</span> from
79857+
<var>response</var>.</p></li>
79858+
79859+
<li><p>If <var>COEP</var> is "<code data-x="">require-corp</code>", then return "<code
79860+
data-x="">same-origin-plus-COEP</code>".</p></li>
79861+
</ol>
79862+
</li>
79863+
79864+
<li><p>Return <var>decodedValue</var></p></li>
79865+
</ol>
79866+
79867+
<p>To <dfn data-x="matching-coop">match cross-origin opener policies</dfn>, given a <span
79868+
data-x="cross-origin-opener-policy">COOP</span> <var>A</var>, an <span>origin</span>
79869+
<var>originA</var>, a <span data-x="cross-origin-opener-policy">COOP</span> <var>B</var> and an
79870+
<span>origin</span> <var>originB</var>:</p>
79871+
79872+
<ol>
79873+
<li><p>If <var>A</var> is "<code data-x="">unsafe-none</code>" and <var>B</var> is "<code
79874+
data-x="">unsafe-none</code>", then return true.</p></li>
79875+
79876+
<li><p>If <var>A</var> or <var>B</var> is "<code data-x="">unsafe-none</code>", then return
79877+
false.</p></li>
79878+
79879+
<li><p>If <var>A</var> is the same value as <var>B</var> and
79880+
<var>originA</var> is <span>same origin</span> with <var>originB</var>, then
79881+
return true.</p></li>
79882+
79883+
<li><p>Return false.</p></li>
79884+
</ol>
79885+
79886+
<p>To <dfn data-x="obtain-browsing-context-navigation">obtain a browsing context to use for a
79887+
navigation response</dfn>, given a <span data-x="concept-response">response</span>
79888+
<var>response</var>, a <span data-x="browsing context">browsing context</span>
79889+
<var>browsingContext</var>, a <span>sandboxing flag set</span> <var>sandboxFlags</var>, two <span
79890+
data-x="origin">origins</span> <var>incumbentNavigationOrigin</var>,
79891+
<var>activeDocumentNavigationOrigin</var>, and a <span
79892+
data-x="cross-origin-opener-policy">cross-origin opener policy</span>
79893+
<var>responseCOOP</var>:</p>
79894+
79895+
<ol>
79896+
<li><p>Let <var>activeDocumentCOOP</var> be the <span data-x="concept-document-coop">
79897+
cross-origin opener policy</span> of <var>currentBrowsingContext</var>'s <span>active
79898+
document</span>.</p></li>
79899+
79900+
<li><p>If the result of <span data-x="matching-coop">matching</span>
79901+
<var>activeDocumentCOOP</var>, <var>activeDocumentNavigationOrigin</var>,
79902+
<var>responseCOOP</var> and <var>incumbentNavigationOrigin</var> is true, return
79903+
<var>browsingContext</var>.</p></li>
79904+
79905+
<li>
79906+
<p>If all of the following are true:</p>
79907+
79908+
<ul>
79909+
<li><p><var>currentBrowsingContext</var>'s only entry in its <span>session history</span> is
79910+
the <code>about:blank</code> <code>Document</code> that was added when
79911+
<var>browsingContext</var> was <span data-x="creating a new browsing
79912+
context">created</span>.</p></li>
79913+
79914+
<li><p><var>activeDocumentCOOP</var> is "<code
79915+
data-x="">same-origin-allow-popups</code>".</p></li>
79916+
79917+
<li><p><var>responseCOOP</var> is "<code data-x="">unsafe-none</code>".</p></li>
79918+
</ul>
79919+
79920+
<p>then return <var>browsingContext</var>.</p>
79921+
</li>
79922+
79923+
<li><p>Let <var>newBrowsingContextGroup</var> be the result of <span>creating a new
79924+
browsing context group</span>.</p></li>
79925+
79926+
<li><p>If <var>responseCOOP</var> is "<code data-x="">same-origin-plus-COEP</code>", then set
79927+
<var>newBrowsingContextGroup</var> <span data-x="bcg cross-origin isolated">cross-origin
79928+
isolated</span> to true.</p></li>
79929+
79930+
<li><p>Let <var>newBrowsingContext</var> be the result of <span data-x="creating a new browsing
79931+
context">creating a new browsingContext</span> in <var>newBrowsingContextGroup</var>.</p></li>
79932+
79933+
<li>
79934+
<p>If <var>sandboxFlags</var> is not empty, then:</p>
79935+
<ol>
79936+
<li><p>Assert <var>responseCOOP</var> is "<code data-x="">unsafe-none</code>".</p></li>
79937+
79938+
<li><p>Set <var>newBrowsingContext</var>'s <span>sandboxing flag set</span> to
79939+
<var>sandboxFlags</var>.</p></li>
79940+
</ol>
79941+
</li>
79942+
79943+
<li>
79944+
<p><span data-x="a browsing context is discarded">Discard</span>
79945+
<var>currentBrowsingContext</var>.</p>
79946+
79947+
<p class="note">This does not close <var>currentBrowsingContext</var>'s <span>browsing context
79948+
group</span> except if it was the sole top-level browsing context in which case it could be
79949+
collected</p>
79950+
</li>
79951+
79952+
<li><p>Return <var>newBrowsingContext</var>.</p></li>
79953+
</ol>
79954+
79955+
<p class="XXX">The impact of swapping browsing context groups following a navigation is not
79956+
defined. It is currently under discussion in <a
79957+
href="https://github.com/whatwg/html/issues/5350">issue 5350</a>.</p>
79958+
79959+
79960+
7973979961
<h3 split-filename="history" id="history">Session history and navigation</h3>
7974079962

7974179963
<h4>The session history of browsing contexts</h4>
@@ -82091,6 +82313,45 @@ interface <dfn>Location</dfn> { // but see also <a href="#the-location-interface
8209182313
</div>
8209282314
</li>
8209382315

82316+
<li><p>Let <var>incumbentCOOP</var> be "<code data-x="">unsafe-none</code>".</p></li>
82317+
82318+
<li><p>If <var>browsingContext</var> is a <span>top-level browsing context</span>, then:</p>
82319+
82320+
<ol>
82321+
<li><p>Set <var>incumbentCOOP</var> to the <span
82322+
data-x="cross-origin-opener-policy">cross-origin opener policy</span> <span
82323+
data-x="obtain-coop">obtained</span> given <var>response</var> and
82324+
<var>reservedEnvironment</var>.</p></li>
82325+
82326+
<li>
82327+
<p>If <var>sandboxFlags</var> is not empty and <var>incumbentCOOP</var> is not "<code
82328+
data-x="">unsafe-none</code>", then <span data-x="navigate-ua-inline">display the inline
82329+
content with an appropriate error shown to the user</span>, with the newly created
82330+
<code>Document</code> object's <span>origin</span> set to a new <span
82331+
data-x="concept-origin-opaque">opaque origin</span>, run the <span data-x="environment
82332+
discarding steps">environment discarding steps</span> for <var>reservedEnvironment</var>, and
82333+
return.</p>
82334+
82335+
<p class="note">This results in a network error as one cannot simultaneously provide a clean
82336+
slate to a response using cross-origin opener policy and sandbox the result of navigating to
82337+
that response.</p>
82338+
</li>
82339+
82340+
<li><p>Let <var>newBrowsingContext</var> be the value of <span
82341+
data-x="obtain-browsing-context-navigation">obtaining a browsing context for the navigation
82342+
response</span> given <var>response</var>, <var>browsingContext</var>, <var>sandboxFlags</var>,
82343+
<var>incumbentNavigationOrigin</var>, <var>activeDocumentNavigationOrigin</var>, and
82344+
<var>incumbentCOOP</var>.</p></li>
82345+
82346+
<li><p>Let <var>browsingContextSwitch</var> be false.</p></li>
82347+
82348+
<li><p>If <var>newBrowsingContext</var> is not equal to <var>browsingContext</var>, then set
82349+
<var>browsingContextSwitch</var> to true.</p></li>
82350+
82351+
<li><p>Set <var>browsingContext</var> to the value of <var>newBrowsingContext</var>.</p></li>
82352+
</ol>
82353+
</li>
82354+
8209482355
<li><p>If <var>browsingContext</var>'s only entry in its <span>session history</span> is the
8209582356
initial <code>about:blank</code> <code>Document</code> that was added when
8209682357
<var>browsingContext</var> was <span data-x="creating a new browsing context">created</span>, and
@@ -82134,8 +82395,9 @@ interface <dfn>Location</dfn> { // but see also <a href="#the-location-interface
8213482395
data-x="concept-document-type">type</span> is <var>type</var>, <span
8213582396
data-x="concept-document-content-type">content type</span> is <var>contentType</var>,
8213682397
<span>origin</span> is <var>origin</var>, <span data-x="concept-document-feature-policy">feature
82137-
policy</span> is <var>featurePolicy</var>, and <span>active sandboxing flag set</span> is
82138-
<var>finalSandboxFlags</var>.</p></li>
82398+
policy</span> is <var>featurePolicy</var>, <span>active sandboxing flag set</span> is
82399+
<var>finalSandboxFlags</var>, and <span data-x="concept-document-coop">cross-origin opener
82400+
policy</span> is <var>incumbentCOOP</var>.</p></li>
8213982401

8214082402
<li id="set-the-document's-address"><p>If <var>request</var> is non-null, then set
8214182403
<var>document</var>'s <span data-x="concept-document-url">URL</span> to <var>request</var>'s
@@ -115745,6 +116007,27 @@ interface <dfn>External</dfn> {
115745116007

115746116008
</div>
115747116009

116010+
<h3>`<dfn><code data-x="http-cross-origin-opener-policy">Cross-Origin-Opener-Policy</code></dfn>`</h3>
116011+
116012+
<p>This section describes a header for registration in the Permanent Message Header Field
116013+
Registry. <ref spec=RFC3864></p>
116014+
116015+
<dl>
116016+
<dt>Header field name:</dt>
116017+
<dd>Cross-Origin-Opener-Policy</dd>
116018+
<dt>Applicable protocol:</dt>
116019+
<dd>http</dd>
116020+
<dt>Status:</dt>
116021+
<dd>standard</dd>
116022+
<dt>Author/Change controller:</dt>
116023+
<dd>WHATWG</dd>
116024+
<dt>Specification document(s):</dt>
116025+
<dd>
116026+
This document is the relevant specification.
116027+
</dd>
116028+
<dt>Related information:</dt>
116029+
<dd>None.</dd>
116030+
</dl>
115748116031

115749116032

115750116033
<h2 split-filename="indices" id="index" class="no-num">Index</h2>
@@ -120276,6 +120559,10 @@ INSERT INTERFACES HERE
120276120559
<dt id="refsCOMPUTABLE">[COMPUTABLE]</dt>
120277120560
<dd>(Non-normative) <cite><a href="http://www.turingarchive.org/browse.php/B/12">On computable numbers, with an application to the Entscheidungsproblem</a></cite>, A. Turing. In <cite>Proceedings of the London Mathematical Society</cite>, series 2, volume 42, pages 230-265. London Mathematical Society, 1937.</dd>
120278120561

120562+
<dt id="refsCOEP">[COEP]</dt>
120563+
<dd><cite><a href="https://wicg.github.io/cross-origin-embedder-policy/">Cross-Origin Embedder Policy</a></cite>, M.
120564+
West.</dd>
120565+
120279120566
<dt id="refsCOOKIES">[COOKIES]</dt>
120280120567
<dd><cite><a href="https://tools.ietf.org/html/rfc6265">HTTP State Management Mechanism</a></cite>, A. Barth. IETF.</dd>
120281120568

0 commit comments

Comments
 (0)