# Swagger Swagger UI Cross-Site Scripting in API response rendering

Source: https://junglewise.ai/threats/swagger-swagger-ui-cross-site-scripting-in-api-response-rendering-be1bf724  
Publisher: Junglewise Threat Intelligence, https://junglewise.ai/threats  
Published: 2020-09-11. Updated: 2026-05-13  
License: CC BY 4.0 with a link back

Severity: info · CVSS 6.1 · Published 2020-09-11

Swagger UI, a tool used to visualize and interact with API documentation, is vulnerable to a security flaw that could allow attackers to run malicious scripts in a user's browser. This occurs when the tool displays a response from an API that is unexpectedly formatted as HTML instead of data. If an attacker can trick a user into interacting with a malicious API through the Swagger interface, they could potentially steal session information or perform actions on the user's behalf.

Technologies: [swagger-ui (npm)](https://junglewise.ai/threats/technologies/swagger-ui). Vendors: [npm](https://junglewise.ai/threats/vendors/npm).

## Quick answers

**Is This vulnerability exploited in the wild?** No. Junglewise Threat Intelligence has no report of This vulnerability being exploited in the wild.

**How severe is This vulnerability?** Informational severity, with a CVSS score of 6.1, published 11 September 2020.

**Which products and versions are affected?** swagger-ui (npm) SEMVER:introduced=0,fixed=2.2.1.

**Is there a fix for This vulnerability?** Yes. swagger-ui (npm): upgrade to 2.2.1 or later. Junglewise finds every place you run it, drafts the upgrade and applies it once you approve.

**How is This vulnerability attacked?** It is attacked over the network, in a software library.

**Am I affected?** Check whether you run swagger-ui (npm) at an affected version. Junglewise does that check for you around the clock: connect your code, cloud and domains, and it matches new vulnerabilities like this one against what you actually run and tells you when one reaches you.

## How to fix

- swagger-ui (npm): upgrade to 2.2.1 or later

  ```sh
  npm install swagger-ui@2.2.1
  ```


## Technical details

Swagger UI versions prior to 2.2.1 are vulnerable to reflected Cross-Site Scripting (XSS). The vulnerability exists because the application fails to properly sanitize or encode output when an API endpoint returns a 'text/html' Content-Type, even if the UI expected 'application/json'. An attacker can exploit this by hosting or manipulating an API response to include malicious <script> tags, which are then executed in the context of the Swagger UI web page when a user clicks the 'Try it out!' button. This issue is resolved in version 2.2.1 by ensuring that HTML responses are properly encoded before being rendered.

## Affected products

- Swagger API swagger-ui < 2.2.1

## Timeline

- 2015-04-13: disclosed: Issue reported on GitHub
- 2020-09-11: advisory: GitHub Advisory published

## References

- [https://github.com/swagger-api/swagger-ui/issues/1154](https://github.com/swagger-api/swagger-ui/issues/1154)
- [https://github.com/swagger-api/swagger-ui](https://github.com/swagger-api/swagger-ui)
- [https://www.npmjs.com/advisories/987](https://www.npmjs.com/advisories/987)

## Related threats

- [swagger-ui cross-site scripting in key names](https://junglewise.ai/threats/cve-2016-1000229-swagger-ui-cross-site-scripting-in-key-names)
- [Swagger UI spoofing attack via URL parameter](https://junglewise.ai/threats/cve-2018-25031-swagger-ui-spoofing-attack-via-url-parameter)
- [Swagger UI phishing vector via URL parameter](https://junglewise.ai/threats/swagger-ui-phishing-vector-via-url-parameter-8eeaa776)
- [Swagger UI Cross-Site Scripting in apiInfo.description](https://junglewise.ai/threats/swagger-ui-cross-site-scripting-in-apiinfo-description-6b3f2dbe)
- [Swagger UI Cross-Site Scripting in method descriptions](https://junglewise.ai/threats/swagger-ui-cross-site-scripting-in-method-descriptions-d34bf589)
