Skip to content
XSS Write-up Intermediate

Exploiting XSS in Swagger UI: Turning APIs into XSS Playground”

Swagger UI allowed loading external OpenAPI definitions via the configUrl parameter without proper validation, enabling reflected cross-site scripting. An attacker could execute arbitrary JavaScript in a victim's session, potentially leading to account takeover if cookies lack HttpOnly protection.

medium.com

Published on medium.com

This write-up details the technical aspects of the vulnerability, affected versions, exploitation, impact, and possible mitigations. Since this vulnerability has not yet been mitigated, I will be referring to the affected program as Target throughout this write-up although they did offer me a swag instead of a bounty…

Eslam Abu Bakr, on medium.com

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 application failed to validate or sanitise the configUrl parameter, allowing untrusted external OpenAPI definitions to be loaded and rendered without proper encoding.

Impact

An attacker could execute arbitrary JavaScript in a victim's session, potentially leading to account takeover, data theft, and session hijacking if cookies are not protected with HttpOnly.

What the attacker needed

Victim clicks a crafted link; attacker hosts a malicious OpenAPI file; cookies not HttpOnly for full impact

The fix

The vulnerability should be fixed by restricting external API definitions, sanitising user input, disabling untrusted config URLs, and implementing HttpOnly and Secure cookies along with a strong Content Security Policy.

How it was found

  1. Host a malicious OpenAPI file (swagger.json or swagger.yaml) on a publicly accessible location.
  2. Craft a URL with the configUrl parameter pointing to the malicious file.
  3. Send the crafted URL to a victim; when visited, the injected JavaScript executes in their session.
  4. If cookies lack HttpOnly, exfiltrate them to an attacker-controlled server to hijack the session.

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 and lets you try out API calls. The problem was that it could be told to load a documentation file from any web address, and if that file contained malicious JavaScript, the browser would run it as if it came from the trusted site. This means an attacker could trick a logged-in user into clicking a link that runs code in their session, potentially stealing their cookies.

What is XSS?

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.