-
Notifications
You must be signed in to change notification settings - Fork 23k
FF145 Relnote: Trusted Types early beta #41518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
a586cfe
16cf6c0
1578ce4
8d2f1d9
067f8b5
a544861
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,7 @@ The **Trusted Types API** gives web developers a way to ensure that input has be | |
|
|
||
| ## Concepts and usage | ||
|
|
||
| Client-side, or DOM-based, XSS attacks happen when data crafted by an attacker is passed to a browser API that executes that data as code. These APIs are known as _injection sinks_. | ||
| Client-side, or DOM-based, XSS attacks happen when data crafted by an attacker is passed to a browser API that executes that data as code. These APIs are known as [_injection sinks_](#injection_sink_interfaces). | ||
|
|
||
| The Trusted Types API distinguishes three sorts of injection sinks: | ||
|
|
||
|
|
@@ -201,6 +201,72 @@ Either way, the injection sink gets sanitized data, and because we could enforce | |
| - {{domxref("TrustedTypePolicyFactory")}} | ||
| - : Creates policies and verifies that Trusted Type object instances were created via one of the policies. | ||
|
|
||
| ### Extensions to other interfaces | ||
|
|
||
| - {{domxref("Window.trustedTypes")}} | ||
| - : Returns the {{domxref("TrustedTypePolicyFactory")}} object associated with the global object in the main thread. | ||
| This is the entry point for using the API in the Window thread. | ||
| - {{domxref("WorkerGlobalScope.trustedTypes")}}. | ||
| - : Returns the {{domxref("TrustedTypePolicyFactory")}} object associated with the global object in a worker. | ||
|
|
||
| ### Extensions to HTTP | ||
|
|
||
| #### `Content-Security-Policy` directives | ||
|
|
||
| - {{CSP("require-trusted-types-for")}} | ||
| - : Enforces that [Trusted Types](/en-US/docs/Web/API/Trusted_Types_API) are passed to DOM XSS [injection sinks](/en-US/docs/Web/API/Trusted_Types_API#concepts_and_usage). | ||
| - {{CSP("trusted-types")}} | ||
| - : Used to specify an allowlist of [Trusted Types](/en-US/docs/Web/API/Trusted_Types_API) policy names. | ||
|
|
||
| #### `Content-Security-Policy` keywords | ||
|
|
||
| - [`trusted-types-eval`](/en-US/docs/Web/HTTP/Reference/Headers/Content-Security-Policy#trusted-types-eval) | ||
| - : Allows [`eval()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval) and similar functions to be used but only when [Trusted Types](/en-US/docs/Web/API/Trusted_Types_API) are supported and enforced. | ||
|
|
||
| ## Injection sink interfaces | ||
|
|
||
| This section provides an list of "direct" injection sink interfaces. | ||
|
||
|
|
||
| Note that there are cases where untrusted strings may be "indirectly injected", such as when an untrusted string is added as the child node of a script element, and then the element is added to the document. | ||
| These cases are evaluated the untrusted script is added to the document. | ||
|
||
|
|
||
| ### TrustedHTML | ||
|
|
||
| - {{domxref("Document.execCommand()")}} with a `commandName` of [`"insertHTML"`](/en-US/docs/Web/API/Document/execCommand#inserthtml) | ||
| - {{domxref("Document.parseHTMLUnsafe_static()")}} | ||
| - {{domxref("Document.write()")}} | ||
| - {{domxref("Document.writeln()")}} | ||
| - {{domxref("DOMParser.parseFromString()")}} | ||
| - {{domxref("Element.innerHTML")}} | ||
| - {{domxref("Element.insertAdjacentHTML")}} | ||
| - {{domxref("Element.outerHTML")}} | ||
| - {{domxref("Element.setHTMLUnsafe()")}} | ||
| - {{domxref("HTMLIFrameElement.srcdoc")}} | ||
| - {{domxref("Range.createContextualFragment()")}} | ||
| - {{domxref("ShadowRoot.innerHTML")}} | ||
| - {{domxref("ShadowRoot.setHTMLUnsafe()")}} | ||
|
|
||
| ### TrustedScript | ||
|
|
||
| - [`eval()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval) | ||
| - [`Element.setAttribute()`](/en-US/docs/Web/API/Element/setAttribute#value) (`value` argument) | ||
| - [`Element.setAttributeNS()`](/en-US/docs/Web/API/Element/setAttributeNS#value) (`value` argument) | ||
| - [`Function()` constructor](/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/Function) | ||
| - {{domxref("HTMLScriptElement.innerText")}} | ||
| - {{domxref("HTMLScriptElement.textContent")}} | ||
| - {{domxref("HTMLScriptElement.text")}} | ||
| - [`window.setTimeout()`](/en-US/docs/Web/API/Window/setTimeout#code) and [`WorkerGlobalScope.setTimeout()`](/en-US/docs/Web/API/WorkerGlobalScope/setTimeout#code) (`code` argument) | ||
| - [`window.setInterval()`](/en-US/docs/Web/API/Window/setInterval#code) and [`WorkerGlobalScope.setInterval()`](/en-US/docs/Web/API/WorkerGlobalScope/setInterval#code) (`code` argument) | ||
|
|
||
| ### TrustedScriptURL | ||
|
|
||
| - {{domxref("HTMLScriptElement.src")}} | ||
| - {{domxref("ServiceWorkerContainer.register()")}} | ||
| - {{domxref("SvgAnimatedString.baseVal")}} | ||
| - {{domxref("WorkerGlobalScope.importScripts()")}} | ||
| - `url` argument to [`Worker()` constructor](/en-US/docs/Web/API/Worker/Worker#url) | ||
| - `url` argument to [`SharedWorker()` constructor](/en-US/docs/Web/API/SharedWorker/SharedWorker#url) | ||
|
|
||
| ## Examples | ||
|
|
||
| In the below example we create a policy that will create {{domxref("TrustedHTML")}} objects using {{domxref("TrustedTypePolicyFactory.createPolicy()")}}. We can then use {{domxref("TrustedTypePolicy.createHTML()")}} to create a sanitized HTML string to be inserted into the document. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[mdn-linter] reported by reviewdog 🐶