GHSL-2021-083: Type confusion in scripttag leads to XSS - CVE-2021-32696
The striptags library fails to sanitise input when an array is passed instead of a string, allowing an attacker to inject HTML and script tags. This can lead to reflected cross-site scripting (XSS) in applications that pass user-controlled arrays to the sanitiser.
Originally disclosed on GitHub Security Lab
A type-confusion vulnerability leads scriptags to incorrectly sanitize dangerous inputs when an attacker is able to send an array (instead of a string) to the striptags function.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The library assumes the input is a string and iterates over its characters, but when given an array it iterates over array elements and fails to sanitise each element properly.
Impact
An attacker could execute arbitrary JavaScript in a victim's browser, leading to reflected XSS.
What the attacker needed
Application passes user input as array to striptags; victim clicks a crafted link
The fix
The vulnerability was fixed by the maintainer.
How it was found
- Set up an Express application that uses striptags to sanitise a query parameter.
- Send a request with the parameter as an array containing a script tag.
- The application reflects the unsanitised script tag, executing JavaScript in the browser.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
The striptags library is supposed to remove dangerous HTML tags from text. But if you give it an array of strings instead of a single string, it gets confused and doesn't remove the tags. An attacker can exploit this to run their own JavaScript in a victim's browser, which is called cross-site scripting (XSS).
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.