Skip to content

DOM Text Injection Leads to HTML Reinterpretation and Cross-Site Scripting via powertip

High
ornicar published GHSA-9xhx-p3c5-p4v6 Apr 13, 2025

Package

powertip.ts (TypeScript)

Affected versions

0

Patched versions

0

Description

document.querySelector('#image-powertip')!.innerHTML = `<img src="${el.dataset.src}"${w}${h}>`;

Extracting text from a DOM node and interpreting it as HTML can lead to a cross-site scripting vulnerability. A webpage with this vulnerability reads text from the DOM, and afterwards adds the text as HTML to the DOM. Using text from the DOM as HTML effectively unescapes the text, and thereby invalidates any escaping done on the text. If an attacker is able to control the safe sanitized text, then this vulnerability can be exploited to perform a cross-site scripting attack.

POC

The following vulnerable shows a webpage using a data-target attribute to select and manipulate a DOM element using the JQuery library. In the vulnerable, the data-target attribute is read into the target variable, and the $ function is then supposed to use the target variable as a CSS selector to determine which element should be manipulated.

$("button").click(function () {
    var target = $(this).attr("data-target");
    $(target).hide();
});

However, if an attacker can control the data-target attribute, then the value of target can be used to cause the $ function to execute arbitrary JavaScript.

The above vulnerability can be fixed by using $.find instead of $. The $.find function will only interpret target as a CSS selector and never as HTML, thereby preventing an XSS attack.

$("button").click(function () {
    var target = $(this).attr("data-target");
	$.find(target).hide();
});

References

DOM based XSS Prevention Cheat Sheet
XSS (Cross Site Scripting) Prevention Cheat Sheet
DOM Based XSS
Types of Cross-Site Scripting
Cross-site scripting
CWE-79
CWE-116

Impact

DOM text reinterpreted as HTML Cross-site Scripting

Severity

High

CVE ID

No known CVE

Weaknesses

Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')

The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. Learn more on MITRE.

Improper Encoding or Escaping of Output

The product prepares a structured message for communication with another component, but encoding or escaping of the data is either missing or done incorrectly. As a result, the intended structure of the message is not preserved. Learn more on MITRE.

Credits