Skip to content

Commit e593d32

Browse files
authored
TrustedTypes: Document.execCommand() with command insertHTML (mdn#42238)
1 parent cbb6b6b commit e593d32

File tree

1 file changed

+10
-1
lines changed
  • files/en-us/web/api/document/execcommand

1 file changed

+10
-1
lines changed

files/en-us/web/api/document/execcommand/index.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,16 @@ execCommand(commandName, showDefaultUI, valueArgument)
7979
- `insertHorizontalRule`
8080
- : Inserts a {{HTMLElement("hr")}} element at the insertion point, or replaces the selection with it.
8181
- `insertHTML`
82-
- : Inserts an HTML string at the insertion point (deletes selection). Requires a valid HTML string as a value argument.
82+
- : Inserts an {{domxref("TrustedHTML")}} instance or string of HTML markup at the insertion point (deletes selection).
83+
This requires valid HTML markup.
84+
85+
> [!WARNING]
86+
> The input is parsed as HTML and written into the DOM.
87+
> APIs like this are known as [injection sinks](/en-US/docs/Web/API/Trusted_Types_API#concepts_and_usage), and are potentially a vector for [cross-site scripting (XSS)](/en-US/docs/Web/Security/Attacks/XSS) attacks, if the input originally came from an attacker.
88+
>
89+
> You can mitigate this risk 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).
90+
> See the [Trusted Types API](/en-US/docs/Web/API/Trusted_Types_API) for more information.
91+
8392
- `insertImage`
8493
- : Inserts an image at the insertion point (deletes selection). Requires a URL string for the image's `src` as a value argument. The requirements for this string are the same as `createLink`.
8594
- `insertOrderedList`

0 commit comments

Comments
 (0)