A computed string is parsed as HTML through innerHTML, insertAdjacentHTML or document.write

tx0/ts:html-string-sinkrecommendedwarningsecurity, cwe-79

What it finds

element.innerHTML = message, node.insertAdjacentHTML("beforeend", row), document.write(html): these parse a string as HTML. If any part of it comes from a user, a URL or a server response, it can carry a <script> or an onerror handler that runs in the page, which is cross-site scripting.

Reported are assignments to innerHTML and outerHTML, calls of insertAdjacentHTML, and document.write and document.writeln on the global document, whose HTML is not a string literal. textContent sets text without parsing it.

From the rule's source, html_string_sink.rs.

Example from the rule's tests
function show(element: HTMLElement, message: string) {  element.innerHTML = "<b>" + message + "</b>";tx0 reports: this sets innerHTML from a computed string  element.innerHTML = "";  element.insertAdjacentHTML("beforeend", message);tx0 reports: insertAdjacentHTML parses this computed string as HTML  document.write(message);tx0 reports: write parses this computed string as HTML  element.textContent = message;}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/ts:html-string-sink" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/ts:html-string-sink] reason="..."

tx0 explain tx0/ts:html-string-sink shows the same in the terminal. Found a false positive? Report it.