Hacking Swagger-UI - from XSS to account takeovers
A DOM-based cross-site scripting (XSS) vulnerability in Swagger UI allowed an attacker to execute arbitrary JavaScript by tricking a victim into visiting a crafted URL. The flaw stemmed from an outdated DOMPurify library and insufficient sanitisation, enabling attackers to steal authentication tokens and potentially take over accounts.
Published on vidocsecurity.com
The most cyber-capable open model, for defenders. Try now >>
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 write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the root cause is an outdated version of the DOMPurify library used for sanitisation, combined with Swagger UI's feature that renders user-supplied API specifications as markdown, allowing a bypass of the sanitiser.
Impact
An attacker could execute arbitrary JavaScript in a victim's browser, potentially leading to account takeover by stealing authentication tokens stored in local storage, as demonstrated in Jamf Pro and GitLab.
What the attacker needed
Victim clicks a crafted link; Swagger UI version >=3.14.1 < 3.38.0; attacker hosts malicious spec file
The fix
The vulnerability was fixed in Swagger UI version 3.38.0 and later; upgrading to the latest version (^4.13.0) or updating the DOMPurify package resolves the issue.
How it was found
- Identify a Swagger UI instance with a vulnerable version (>=3.14.1 < 3.38.0).
- Craft a malicious API specification file containing a DOMPurify bypass payload that does not use a <style> tag.
- Host the specification file on an attacker-controlled server.
- Construct a URL with the configUrl or url parameter pointing to the malicious file.
- Send the URL to a victim to trigger the XSS.
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 write-up has not been written yet. The Original tab links to the source.
Swagger UI is a tool that displays API documentation. It had a security hole where a malicious link could run harmful code in a victim's browser, letting attackers steal login tokens. This 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.