Skip to content

Commit e6c299f

Browse files
Apply suggestions from code review
Co-authored-by: sideshowbarker <[email protected]>
1 parent 4f1bf2e commit e6c299f

File tree

1 file changed

+5
-5
lines changed
  • files/en-us/web/api/shadowroot/innerhtml

1 file changed

+5
-5
lines changed

files/en-us/web/api/shadowroot/innerhtml/index.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const name = "<img src='x' onerror='alert(1)'>";
5050
shadowRoot.innerHTML = name; // shows the alert
5151
```
5252

53-
You can mitigate these issues by always assigning {{domxref("TrustedHTML")}} objects instead of strings, and [enforcing trusted type](/en-US/docs/Web/API/Trusted_Types_API#using_a_csp_to_enforce_trusted_types) using the [`require-trusted-types-for`](/en-US/docs/Web/HTTP/Reference/Headers/Content-Security-Policy/require-trusted-types-for) CSP directive.
53+
You can mitigate these issues by always assigning {{domxref("TrustedHTML")}} objects instead of strings, and [enforcing trusted types](/en-US/docs/Web/API/Trusted_Types_API#using_a_csp_to_enforce_trusted_types) using the [`require-trusted-types-for`](/en-US/docs/Web/HTTP/Reference/Headers/Content-Security-Policy/require-trusted-types-for) CSP directive.
5454
This ensures that the input is passed through a transformation function, which has the chance to [sanitize](/en-US/docs/Web/Security/Attacks/XSS#sanitization) the input to remove potentially dangerous markup before it is injected.
5555

5656
## Examples
@@ -84,15 +84,15 @@ In this example we'll replace an element's DOM by assigning HTML to the element'
8484
To mitigate the risk of XSS, we'll first create a `TrustedHTML` object from the string containing the HTML, and then assign that object to `innerHTML`.
8585

8686
Trusted types are not yet supported on all browsers, so first we define the [trusted types tinyfill](/en-US/docs/Web/API/Trusted_Types_API#trusted_types_tinyfill).
87-
This acts as a transparent replacement for the trusted types JavaScript API:
87+
This acts as a transparent replacement for the Trusted Types JavaScript API:
8888

8989
```js
9090
if (typeof trustedTypes === "undefined")
9191
trustedTypes = { createPolicy: (n, rules) => rules };
9292
```
9393

94-
Next we create a {{domxref("TrustedTypePolicy")}} that defines a {{domxref("TrustedTypePolicy/createHTML", "createHTML()")}} for transforming an input string into {{domxref("TrustedHTML")}} instances.
95-
Commonly implementations of `createHTML()` use a library such as [DOMPurify](https://github.com/cure53/DOMPurify) to sanitize the input as shown below:
94+
Next we create a {{domxref("TrustedTypePolicy")}} that defines a {{domxref("TrustedTypePolicy/createHTML", "createHTML()")}} method for transforming an input string into {{domxref("TrustedHTML")}} instances.
95+
Commonly, implementations of `createHTML()` use a library such as [DOMPurify](https://github.com/cure53/DOMPurify) to sanitize the input as shown below:
9696

9797
```js
9898
const policy = trustedTypes.createPolicy("my-policy", {
@@ -118,7 +118,7 @@ shadowRoot.innerHTML = trustedHTML;
118118
```
119119

120120
> [!WARNING]
121-
> While you can directly assign a string to `innerHTML` this is a [security risk](#security_considerations) if the string to be inserted might contain potentially malicious content.
121+
> While you can directly assign a string to `innerHTML`, this is a [security risk](#security_considerations) if the string to be inserted might contain potentially malicious content.
122122
123123
## Specifications
124124

0 commit comments

Comments
 (0)