Skip to content

Commit 9ec0f8b

Browse files
authored
FF140 escaping < and > to &lt; and &gt; in attributes when serializing HTML (#39639)
1 parent 1809464 commit 9ec0f8b

File tree

6 files changed

+27
-63
lines changed

6 files changed

+27
-63
lines changed

files/en-us/mozilla/firefox/experimental_features/index.md

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,49 +1057,6 @@ The [HTML Sanitizer API](/en-US/docs/Web/API/HTML_Sanitizer_API) allow developer
10571057
</tbody>
10581058
</table>
10591059

1060-
### Escape < and > in attributes when serializing HTML
1061-
1062-
Firefox replaces the `<` and `>` characters with `&lt;` and `&gt;` (respectively) in attributes when serializing HTML.
1063-
This prevents certain exploits where HTML is serialized and then injected back into the DOM.
1064-
The affected methods and properties are: {{domxref("Element.innerHTML")}}, {{domxref("Element.outerHTML")}}, {{domxref("Element.getHTML()")}}, {{domxref("ShadowRoot.innerHTML")}}, and {{domxref("ShadowRoot.getHTML()")}}.
1065-
([Firefox bug 1941347](https://bugzil.la/1941347)).
1066-
1067-
<table>
1068-
<thead>
1069-
<tr>
1070-
<th>Release channel</th>
1071-
<th>Version added</th>
1072-
<th>Enabled by default?</th>
1073-
</tr>
1074-
</thead>
1075-
<tbody>
1076-
<tr>
1077-
<th>Nightly</th>
1078-
<td>139</td>
1079-
<td>Yes</td>
1080-
</tr>
1081-
<tr>
1082-
<th>Developer Edition</th>
1083-
<td>139</td>
1084-
<td>No</td>
1085-
</tr>
1086-
<tr>
1087-
<th>Beta</th>
1088-
<td>139</td>
1089-
<td>No</td>
1090-
</tr>
1091-
<tr>
1092-
<th>Release</th>
1093-
<td>139</td>
1094-
<td>No</td>
1095-
</tr>
1096-
<tr>
1097-
<th>Preference name</th>
1098-
<td colspan="2"><code>dom.security.html_serialization_escape_lt_gt</code></td>
1099-
</tr>
1100-
</tbody>
1101-
</table>
1102-
11031060
### Removal of MutationEvent
11041061

11051062
{{domxref("MutationEvent")}} and its associated events (`DOMSubtreeModified`, `DOMNodeInserted`, `DOMNodeRemoved`, `DOMCharacterDataModified`, `DOMAttrModified`) are on the path for removal, and have been disabled on nightly.

files/en-us/web/api/element/gethtml/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ The options can be used to include nested shadow roots that have been set as {{d
1515

1616
Without arguments, child nodes that are shadow roots are not serialized, and this method behaves in the same way as reading the value of {{domxref("Element.innerHTML")}}.
1717

18+
Note that some browsers serialize the `<` and `>` characters as `&lt;` and `&gt;` when they appear in attribute values (see [Browser compatibility](#browser_compatibility)).
19+
This is to prevent a potential security vulnerability ([mutation XSS](https://research.securitum.com/dompurify-bypass-using-mxss/)) in which an attacker can craft input that bypasses a [sanitization function](/en-US/docs/Web/Security/Attacks/XSS#sanitization), enabling a cross-site scripting (XSS) attack.
20+
1821
## Syntax
1922

2023
```js-nolint

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ browser-compat: api.Element.innerHTML
88

99
{{APIRef("DOM")}}
1010

11-
The {{domxref("Element")}} property **`innerHTML`** gets or sets the HTML or XML markup contained within the element.
11+
The **`innerHTML`** property of the {{domxref("Element")}} interface gets or sets the HTML or XML markup contained within the element.
1212

1313
More precisely, `innerHTML` gets a serialization of the nested child DOM elements within the element, or sets HTML or XML that should be parsed to replace the DOM tree within the element.
1414

@@ -20,6 +20,9 @@ Similarly, when setting element content using `innerHTML`, the HTML string is pa
2020
So for example [`<template>`](/en-US/docs/Web/HTML/Reference/Elements/template) is parsed into as {{domxref("HTMLTemplateElement")}}, whether or not the [`shadowrootmode`](/en-US/docs/Web/HTML/Reference/Elements/template#shadowrootmode) attribute is specified
2121
In order to set an element's contents from an HTML string that includes declarative shadow roots, you must use either {{domxref("Element.setHTMLUnsafe()")}} or {{domxref("ShadowRoot.setHTMLUnsafe()")}}.
2222

23+
Note that some browsers serialize `<` and `>` in attributes as `&lt;` and `&gt;` when reading the HTML (see [Browser compatibility](#browser_compatibility)).
24+
This prevents certain exploits where code becomes executable when serialized and then deserialized into HTML.
25+
2326
## Value
2427

2528
A string containing the HTML serialization of the element's descendants.
@@ -42,7 +45,7 @@ Reading `innerHTML` causes the user agent to serialize the HTML or XML fragment
4245
The resulting string is returned.
4346

4447
```js
45-
let contents = myElement.innerHTML;
48+
const contents = myElement.innerHTML;
4649
```
4750

4851
This lets you look at the HTML markup of the element's content nodes.

files/en-us/web/api/element/outerhtml/index.md

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,27 @@ browser-compat: api.Element.outerHTML
99
{{APIRef("DOM")}}
1010

1111
The **`outerHTML`** attribute of the {{ domxref("Element") }}
12-
DOM interface gets the serialized HTML fragment describing the element including its
13-
descendants. It can also be set to replace the element with nodes parsed from the given
14-
string.
12+
DOM interface gets the serialized HTML fragment describing the element including its descendants.
13+
It can also be set to replace the element with nodes parsed from the given string.
1514

16-
To only obtain the HTML representation of the contents of an element, or to replace the
17-
contents of an element, use the {{domxref("Element.innerHTML", "innerHTML")}} property
18-
instead.
15+
To only obtain the HTML representation of the contents of an element, or to replace the contents of an element, use the {{domxref("Element.innerHTML", "innerHTML")}} property instead.
16+
17+
Note that some browsers serialize `<` and `>` in attributes as `&lt;` and `&gt;` when reading the HTML (see [Browser compatibility](#browser_compatibility)).
18+
This prevents certain exploits where code becomes executable when serialized and then deserialized into HTML.
1919

2020
## Value
2121

22-
Reading the value of `outerHTML` returns a string
23-
containing an HTML serialization of the `element` and its descendants.
24-
Setting the value of `outerHTML` replaces the element and all of its
25-
descendants with a new DOM tree constructed by parsing the specified
26-
`htmlString`.
22+
Reading the value of `outerHTML` returns a string containing an HTML serialization of the `element` and its descendants.
23+
Setting the value of `outerHTML` replaces the element and all of its descendants with a new DOM tree constructed by parsing the specified `htmlString`.
2724

2825
When set to the `null` value, that `null` value is converted to the empty string (`""`), so `elt.outerHTML = null` is equivalent to `elt.outerHTML = ""`.
2926

3027
### Exceptions
3128

3229
- `SyntaxError` {{domxref("DOMException")}}
33-
- : Thrown if an attempt was made to set `outerHTML` using an HTML string which is not
34-
valid.
30+
- : Thrown if an attempt was made to set `outerHTML` using an HTML string which is not valid.
3531
- `NoModificationAllowedError` {{domxref("DOMException")}}
36-
- : Thrown if an attempt was made to set `outerHTML` on an element which is a direct
37-
child of a {{domxref("Document")}}, such as {{domxref("Document.documentElement")}}.
32+
- : Thrown if an attempt was made to set `outerHTML` on an element which is a direct child of a {{domxref("Document")}}, such as {{domxref("Document.documentElement")}}.
3833

3934
## Examples
4035

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ The options can be used to include nested shadow roots that have been set as {{d
1515

1616
Without arguments, child nodes that are shadow roots are not serialized, and this method behaves in the same way as reading the value of {{domxref("Element.innerHTML")}}.
1717

18+
Note that some browsers serialize `<` and `>` in attributes as `&lt;` and `&gt;` in the returned HTML (see [Browser compatibility](#browser_compatibility)).
19+
This prevents certain exploits where code becomes executable when serialized and then deserialized into HTML.
20+
1821
## Syntax
1922

2023
```js-nolint

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ browser-compat: api.ShadowRoot.innerHTML
88

99
{{APIRef("Shadow DOM")}}
1010

11-
The **`innerHTML`** property of the {{domxref("ShadowRoot")}}
12-
interface sets or returns a reference to the DOM tree inside the
13-
`ShadowRoot`.
11+
The **`innerHTML`** property of the {{domxref("ShadowRoot")}} interface sets gets or sets the HTML markup to the DOM tree inside the `ShadowRoot`.
12+
13+
Note that some browsers serialize `<` and `>` in attributes as `&lt;` and `&gt;` when reading the HTML (see [Browser compatibility](#browser_compatibility)).
14+
This prevents certain exploits where code becomes executable when serialized and then deserialized into HTML.
1415

1516
## Value
1617

@@ -20,6 +21,8 @@ When set to the `null` value, that `null` value is converted to the empty string
2021

2122
## Examples
2223

24+
### Setting the innerHTML of a Shadow root
25+
2326
```js
2427
let customElem = document.querySelector("my-shadow-dom-element");
2528
let shadow = customElem.shadowRoot;

0 commit comments

Comments
 (0)