How I Tricked a Swagger UI into Showing a Fake Login Page
A Swagger UI page accepted an external configuration URL via the configUrl parameter, allowing an attacker to load a malicious OpenAPI specification. The attacker could render a fake login form on the legitimate domain, potentially tricking users into submitting credentials.
Published on medium.com
Hey, bug hunters and tech nerds! So, I was recently digging into a web app for a bug bounty program, and I stumbled onto something wild.
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 Swagger UI instance did not restrict the configUrl parameter to trusted sources, allowing external OpenAPI specifications to be loaded and their HTML content rendered.
Impact
An attacker could host a fake login form on a trusted domain to phish credentials from employees or users, potentially leading to account takeovers or data breaches.
What the attacker needed
Swagger UI accessible with configUrl parameter; Attacker can host a malicious OpenAPI file; Victim clicks a crafted URL
The fix
Restrict the configUrl parameter to trusted domains, add a Content-Security-Policy, sanitise HTML in description fields, and protect Swagger UI behind authentication.
How it was found
- Find a Swagger UI page on a subdomain.
- Craft a malicious OpenAPI specification file containing HTML for a fake login form.
- Host the file on an external server.
- Load the Swagger UI page with the configUrl parameter pointing to the malicious file.
- Observe the fake login form rendered on the legitimate domain.
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 test API endpoints. It can load external configuration files from a URL. If that URL is not restricted, an attacker can supply their own file containing HTML, which the page then displays as part of the trusted site. This can be used to show a fake login form and steal credentials.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.