Skip to content

Commit 3c5355d

Browse files
authored
Remove fromLiteral from spec. (#405)
1 parent c8aae12 commit 3c5355d

File tree

5 files changed

+185
-367
lines changed

5 files changed

+185
-367
lines changed

explainer.md

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -213,26 +213,6 @@ trustedTypes.createPolicy('default', {
213213
This mechanism complements CSP's `'unsafe-inline'`, allowing the authors to enable strong security
214214
controls in their application even if it occasionally uses `javascript:` URLs for legitimate purposes.
215215

216-
### Source Literals
217-
218-
XSS is an unintended modification of a site's source code. Wrapping literals
219-
from the original JavaScript resource - which by definition aren't XSS - can be
220-
cumbersome. Trusted Types provides a way to easily wrap source literals in
221-
Trusted Types by using the tagged template syntax and the `fromLiteral` methods,
222-
in a way that cannot be spoofed at runtime:
223-
224-
``` javascript
225-
const value = TrustedHTML.fromLiteral`<b>Hello there.</b>`;
226-
```
227-
228-
Note that template literals are passed as arrays of strings to the tag functions.
229-
`fromLiteral` checks that a passed-in value is actually a template literal
230-
and not dynamically constructed.
231-
232-
``` javascript
233-
TrustedHTML.fromLiteral(["<b>Hello there.</b>"]); // Throws.
234-
```
235-
236216
### DOM Sinks
237217

238218
* **HTML Contexts**: Given something like `typedef (DOMString or TrustedHTML) HTMLString`, we'd

spec/index.bs

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,18 @@ WPT Path Prefix: /trusted-types/
2121
block-Document-execCommand.html
2222
block-Node-multiple-arguments.html
2323
block-string-assignment-to-attribute-via-attribute-node.html
24+
block-string-assignment-to-Document-parseHTMLUnsafe.html
2425
block-string-assignment-to-Document-write.html
2526
block-string-assignment-to-DOMParser-parseFromString.html
2627
block-string-assignment-to-DOMWindowTimers-setTimeout-setInterval.html
2728
block-string-assignment-to-Element-insertAdjacentHTML.html
2829
block-string-assignment-to-Element-outerHTML.html
2930
block-string-assignment-to-Element-setAttribute.html
3031
block-string-assignment-to-Element-setAttributeNS.html
32+
block-string-assignment-to-Element-setHTMLUnsafe.html
3133
block-string-assignment-to-HTMLElement-generic.html
3234
block-string-assignment-to-Range-createContextualFragment.html
35+
block-string-assignment-to-ShadowRoot-setHTMLUnsafe.html
3336
block-text-node-insertion-into-script-element.html
3437
csp-block-eval.html
3538
default-policy-callback-arguments.html
@@ -73,7 +76,6 @@ trusted-types-eval-reporting-no-unsafe-eval.html
7376
trusted-types-eval-reporting-report-only.html
7477
trusted-types-eval-reporting.html
7578
trusted-types-event-handlers.html
76-
trusted-types-from-literal.html
7779
trusted-types-navigation.html
7880
trusted-types-report-only.html
7981
trusted-types-reporting-check-report.html
@@ -85,7 +87,6 @@ TrustedType-AttributeNodes.html
8587
TrustedTypePolicy-createXXX.html
8688
TrustedTypePolicy-CSP-no-name.html
8789
TrustedTypePolicy-CSP-wildcard.html
88-
TrustedTypePolicyFactory-blocking.html
8990
TrustedTypePolicyFactory-constants.html
9091
TrustedTypePolicyFactory-createPolicy-createXYZTests.html
9192
TrustedTypePolicyFactory-createPolicy-cspTests-noNamesGiven.html
@@ -380,7 +381,6 @@ wrappers around a string, constructed via a {{TrustedTypePolicy}}'s
380381
interface TrustedHTML {
381382
stringifier;
382383
DOMString toJSON();
383-
static TrustedHTML fromLiteral(object templateStringsArray);
384384
};
385385
</pre>
386386

@@ -393,9 +393,6 @@ will never change during its lifetime.
393393
TrustedHTML object are to return the value from its
394394
`[[Data]]` internal slot.
395395

396-
The <dfn method for="TrustedHTML">fromLiteral(object templateStringsArray)</dfn> method, when invoked, returns the result of executing a [$Create a Trusted Type from literal$] algorithm,
397-
with {{TrustedHTML}} as |type| and |templateStringsArray| as |template|.
398-
399396
### <dfn interface>TrustedScript</dfn> ### {#trusted-script}
400397

401398
The TrustedScript interface represents a string with an uncompiled
@@ -410,7 +407,6 @@ around a string, constructed via a {{TrustedTypePolicy}}'s
410407
interface TrustedScript {
411408
stringifier;
412409
DOMString toJSON();
413-
static TrustedScript fromLiteral(object templateStringsArray);
414410
};
415411
</pre>
416412

@@ -423,9 +419,6 @@ will never change during its lifetime.
423419
TrustedScript object are to return the value from its
424420
`[[Data]]` internal slot.
425421

426-
The <dfn method for="TrustedScript">fromLiteral(object templateStringsArray)</dfn> method, when invoked, returns the result of executing a [$Create a Trusted Type from literal$] algorithm,
427-
with {{TrustedScript}} as |type| and |templateStringsArray| as |template|.
428-
429422
### <dfn interface>TrustedScriptURL</dfn> ### {#trused-script-url}
430423

431424
The TrustedScriptURL interface represents a string that a developer
@@ -440,7 +433,6 @@ string, constructed via a {{TrustedTypePolicy}}'s
440433
interface TrustedScriptURL {
441434
stringifier;
442435
USVString toJSON();
443-
static TrustedScriptURL fromLiteral(object templateStringsArray);
444436
};
445437
</pre>
446438

@@ -453,9 +445,6 @@ will never change during its lifetime.
453445
TrustedScriptURL object are to return the value from its
454446
`[[Data]]` internal slot.
455447

456-
The <dfn method for="TrustedScriptURL">fromLiteral(object templateStringsArray)</dfn> method, when invoked, returns the result of executing a [$Create a Trusted Type from literal$] algorithm,
457-
with {{TrustedScriptURL}} as |type| and |templateStringsArray| as |template|.
458-
459448
## <dfn>Policies</dfn> ## {#policies-hdr}
460449

461450
Trusted Types can only be created via user-defined
@@ -1026,29 +1015,6 @@ a string |value|, a list |arguments|, and a boolean |throwIfMissing|, execute th
10261015
and [[ECMASCRIPT#sec-method|callback **this** value]] set to `null`, rethrowing any exceptions.
10271016
1. Return |policyValue|.
10281017

1029-
## <dfn abstract-op>Create a Trusted Type from literal</dfn> ## {#create-a-trusted-type-from-literal-algorithm}
1030-
1031-
Given a {{TrustedType}} type |type| and an object |template|, execute the following steps:
1032-
1033-
1. If [$check templatedness$] of |template| returns false, throw a {{TypeError}}.
1034-
1. If [$Get$](|template|, "length") is not equal to 1, throw a {{TypeError}}.
1035-
1. Let |templatedValue| be the result of [$Get$](|template|, 0).
1036-
1. If |type| is {{TrustedHTML}}, perform the following steps:
1037-
1. Let |templateNode| be the results of [=create an element|creating an element=] given "template", the [=HTML namespace=] and [=current global object=]'s [=associated Document=].
1038-
1. Assert: |templateNode| is {{HTMLTemplateElement}}.
1039-
1. Let |fragment| be the result of invoking [$fragment parsing algorithm$], with |templatedValue| as <var ignore>markup</var>, and |templateNode| as a <var ignore>context element</var>.
1040-
1. Set |templatedValue| to be the result of invoking [=HTML fragment serialization algorithm=], with |fragment| as <var ignore>the node</var>.
1041-
1042-
1. Return a new instance of an interface |type|, with its `[[Data]]` internal slot value set to |templatedValue|.
1043-
1044-
## Check templatedness of an object ## {#check-templatedness-algorithm}
1045-
1046-
To <dfn abstract-op>check templatedness</dfn> of an object |value|, perform the following steps. They return a boolean value:
1047-
1048-
1. Let |realm| be the <a>current Realm Record</a>.
1049-
1. For each |item| of |realm|.\[[TemplateMap]], if |item|.\[[Array]] is |value|, return true.
1050-
1. Return false.
1051-
10521018
## <dfn abstract-op>Get Trusted Type compliant string</dfn> ## {#get-trusted-type-compliant-string-algorithm}
10531019

10541020
This algorithm will return a string that can be used with an
@@ -1643,8 +1609,8 @@ Content-Security-Policy: require-trusted-types-for 'script'; trusted-types one t
16431609

16441610
<div class="example" id="header-that-allows-no-policy-names">
16451611
An empty [=directive=] [=directive/value=] indicates policies may not be created,
1646-
and sinks expect Trusted Type values, i.e. DOM XSS [=injection sinks=] cannot be used
1647-
with dynamic values. Values for those sinks can only be created by <code>fromLiteral</code> tag functions.
1612+
and sinks expect Trusted Type values, i.e. no DOM XSS [=injection sinks=] can be used
1613+
at all.
16481614
<pre class="http">
16491615
Content-Security-Policy: trusted-types; require-trusted-types-for 'script'
16501616
</pre>

0 commit comments

Comments
 (0)