Skip to content

Commit

Permalink
'require-trusted-types-for' works only in secure contexts. (#274)
Browse files Browse the repository at this point in the history
Fixes #259.
  • Loading branch information
koto authored Mar 16, 2020
1 parent cddf329 commit 4a8cc92
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
24 changes: 20 additions & 4 deletions dist/spec/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@
</style>
<meta content="Bikeshed version 0dd2bba6dfda6c3168490a3a3044dd1d0b1ef8e0" name="generator">
<link href="https://w3c.github.io/webappsec-trusted-types/dist/spec/" rel="canonical">
<meta content="05db7c24182f222e6118fb8b1f032ccb1f76a50e" name="document-revision">
<meta content="cddf3291b629f4e25e18c1f59ad10df6fc7d25dd" name="document-revision">
<style>/* style-md-lists */

/* This is a weird hack for me not yet following the commonmark spec
Expand Down Expand Up @@ -1461,7 +1461,7 @@
<div class="head">
<p data-fill-with="logo"><a class="logo" href="https://www.w3.org/"> <img alt="W3C" height="48" src="https://www.w3.org/StyleSheets/TR/2016/logos/W3C" width="72"> </a> </p>
<h1 class="p-name no-ref" id="title">Trusted Types</h1>
<h2 class="no-num no-toc no-ref heading settled" id="subtitle"><span class="content">Editor’s Draft, <time class="dt-updated" datetime="2020-03-12">12 March 2020</time></span></h2>
<h2 class="no-num no-toc no-ref heading settled" id="subtitle"><span class="content">Editor’s Draft, <time class="dt-updated" datetime="2020-03-16">16 March 2020</time></span></h2>
<div data-fill-with="spec-metadata">
<dl>
<dt>This version:
Expand Down Expand Up @@ -3117,6 +3117,9 @@ <h5 class="heading settled" data-level="4.7.1.1" id="require-trusted-types-for-p
<p>Given a <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-request" id="ref-for-concept-request">request</a> (<var>request</var>), a string <var>navigation type</var> and a <a data-link-type="dfn">policy</a> (<var>policy</var>), this algorithm returns <code>"Blocked"</code> if a navigation violates the <code class="idl"><a data-link-type="idl">require-trusted-types-for</a></code> directive’s constraints and <code>"Allowed"</code> otherwise. This constitutes the <code class="idl"><a data-link-type="idl">require-trusted-types-for</a></code> directive’s <a data-link-type="dfn" href="https://w3c.github.io/webappsec-csp/#directive-pre-navigation-check" id="ref-for-directive-pre-navigation-check">pre-navigation check</a>:</p>
<p class="note" role="note"><span>Note:</span> This algorithm assures that the code to be executed by a navigation to a <code>javascript:</code> URL will have to pass through a <a data-link-type="dfn" href="#default-policy" id="ref-for-default-policy">default policy</a>’s <code>createScript</code> function, in addition to all other restrictions imposed by other CSP directives.</p>
<ol>
<li data-md>
<p>If <var>request</var>’s <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-request-client" id="ref-for-concept-request-client">client</a> is not a <a data-link-type="dfn" href="https://w3c.github.io/webappsec-secure-contexts/#secure-contexts" id="ref-for-secure-contexts">secure context</a>, return <code>"Allowed"</code> and abort further steps.</p>
<p class="note" role="note"><span>Note:</span> <code>require-trusted-types-for</code> directive is recognized only for secure contexts.</p>
<li data-md>
<p>If <var>request</var>’s <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-request-url" id="ref-for-concept-request-url">url</a>'s <a data-link-type="dfn" href="https://url.spec.whatwg.org/#concept-url-scheme" id="ref-for-concept-url-scheme">scheme</a> is not <code>"javascript"</code>, return <code>"Allowed"</code> and abort further steps.</p>
<li data-md>
Expand All @@ -3129,7 +3132,7 @@ <h5 class="heading settled" data-level="4.7.1.1" id="require-trusted-types-for-p
<li data-md>
<p><code class="idl"><a data-link-type="idl" href="#trustedscript" id="ref-for-trustedscript①①">TrustedScript</a></code> as <var>expectedType</var></p>
<li data-md>
<p><var>request</var>’s <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-request-client" id="ref-for-concept-request-client">clients</a>'s <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/webappapis.html#concept-settings-object-global" id="ref-for-concept-settings-object-global">global object</a> as <var>global</var></p>
<p><var>request</var>’s <a data-link-type="dfn" href="https://fetch.spec.whatwg.org/#concept-request-client" id="ref-for-concept-request-client">clients</a>'s <a data-link-type="dfn" href="https://html.spec.whatwg.org/multipage/webappapis.html#concept-settings-object-global" id="ref-for-concept-settings-object-global">global object</a> as <var>global</var></p>
<li data-md>
<p><var>encodedScriptSource</var> as <var>input</var></p>
<li data-md>
Expand Down Expand Up @@ -3883,7 +3886,7 @@ <h3 class="no-num no-ref heading settled" id="index-defined-here"><span class="c
<aside class="dfn-panel" data-for="term-for-concept-request-client">
<a href="https://fetch.spec.whatwg.org/#concept-request-client">https://fetch.spec.whatwg.org/#concept-request-client</a><b>Referenced in:</b>
<ul>
<li><a href="#ref-for-concept-request-client">4.7.1.1. require-trusted-types-for Pre-Navigation check</a>
<li><a href="#ref-for-concept-request-client">4.7.1.1. require-trusted-types-for Pre-Navigation check</a> <a href="#ref-for-concept-request-client①">(2)</a>
</ul>
</aside>
<aside class="dfn-panel" data-for="term-for-local-scheme">
Expand Down Expand Up @@ -4076,6 +4079,12 @@ <h3 class="no-num no-ref heading settled" id="index-defined-here"><span class="c
<li><a href="#ref-for-ordered-set">2.3.1. TrustedTypePolicyFactory</a>
</ul>
</aside>
<aside class="dfn-panel" data-for="term-for-secure-contexts">
<a href="https://w3c.github.io/webappsec-secure-contexts/#secure-contexts">https://w3c.github.io/webappsec-secure-contexts/#secure-contexts</a><b>Referenced in:</b>
<ul>
<li><a href="#ref-for-secure-contexts">4.7.1.1. require-trusted-types-for Pre-Navigation check</a>
</ul>
</aside>
<aside class="dfn-panel" data-for="term-for-dictdef-registrationoptions">
<a href="https://w3c.github.io/ServiceWorker/#dictdef-registrationoptions">https://w3c.github.io/ServiceWorker/#dictdef-registrationoptions</a><b>Referenced in:</b>
<ul>
Expand Down Expand Up @@ -4424,6 +4433,11 @@ <h3 class="no-num no-ref heading settled" id="index-defined-elsewhere"><span cla
<li><span class="dfn-paneled" id="term-for-html-namespace" style="color:initial">html namespace</span>
<li><span class="dfn-paneled" id="term-for-ordered-set" style="color:initial">ordered set</span>
</ul>
<li>
<a data-link-type="biblio">[secure-contexts]</a> defines the following terms:
<ul>
<li><span class="dfn-paneled" id="term-for-secure-contexts" style="color:initial">secure contexts</span>
</ul>
<li>
<a data-link-type="biblio">[service-workers-1]</a> defines the following terms:
<ul>
Expand Down Expand Up @@ -4497,6 +4511,8 @@ <h3 class="no-num no-ref heading settled" id="normative"><span class="content">N
<dd>Anne van Kesteren; Domenic Denicola. <a href="https://infra.spec.whatwg.org/">Infra Standard</a>. Living Standard. URL: <a href="https://infra.spec.whatwg.org/">https://infra.spec.whatwg.org/</a>
<dt id="biblio-rfc2119">[RFC2119]
<dd>S. Bradner. <a href="https://tools.ietf.org/html/rfc2119">Key words for use in RFCs to Indicate Requirement Levels</a>. March 1997. Best Current Practice. URL: <a href="https://tools.ietf.org/html/rfc2119">https://tools.ietf.org/html/rfc2119</a>
<dt id="biblio-secure-contexts">[SECURE-CONTEXTS]
<dd>Mike West. <a href="https://www.w3.org/TR/secure-contexts/">Secure Contexts</a>. 15 September 2016. CR. URL: <a href="https://www.w3.org/TR/secure-contexts/">https://www.w3.org/TR/secure-contexts/</a>
<dt id="biblio-service-workers-1">[SERVICE-WORKERS-1]
<dd>Alex Russell; et al. <a href="https://www.w3.org/TR/service-workers-1/">Service Workers 1</a>. 13 August 2019. WD. URL: <a href="https://www.w3.org/TR/service-workers-1/">https://www.w3.org/TR/service-workers-1/</a>
<dt id="biblio-svg2">[SVG2]
Expand Down
3 changes: 3 additions & 0 deletions spec/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1691,6 +1691,9 @@ otherwise. This constitutes the {{#require-trusted-types-for-directive|require-t
Note: This algorithm assures that the code to be executed by a navigation to a `javascript:` URL will have to pass through a
<a>default policy</a>'s `createScript` function, in addition to all other restrictions imposed by other CSP directives.

1. If |request|'s [=request/client=] is not a [=secure context=], return `"Allowed"` and abort further steps.

Note: `require-trusted-types-for` directive is recognized only for secure contexts.
1. If |request|'s [=request/url=]'s [=url/scheme=] is not `"javascript"`, return `"Allowed"` and abort further steps.
1. Let |urlString| be the result of running the [=URL serializer=] on |request|'s [=request/url=].
1. Let |encodedScriptSource| be the result of removing the leading `"javascript:"` from |urlString|.
Expand Down

0 comments on commit 4a8cc92

Please sign in to comment.