# Swagger UI Cross-Site Scripting in apiInfo.description

Source: https://junglewise.ai/threats/swagger-ui-cross-site-scripting-in-apiinfo-description-6b3f2dbe  
Publisher: Junglewise Threat Intelligence, https://junglewise.ai/threats  
Published: 2020-09-11. Updated: 2026-09-25  
License: CC BY 4.0 with a link back

Severity: info · Published 2020-09-11

Swagger UI is a popular open-source tool for generating interactive API documentation from API specifications. Versions before 2.2.1 fail to properly sanitize HTML content in the API description field, allowing attackers to inject malicious JavaScript code that executes in users' browsers when viewing the API documentation.

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, 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.

**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

This is a Cross-Site Scripting (CWE-79) vulnerability in the swagger-ui library affecting all versions prior to 2.2.1. The vulnerability exists in the swagger.apiInfo.description field, which accepts and renders HTML without proper sanitization. An attacker can inject arbitrary JavaScript by crafting a malicious API specification with script tags or event handlers in the description field. When a user views the generated documentation, the injected script executes in their browser context, potentially allowing session hijacking, credential theft, or malware distribution. The fix was released in version 2.2.1 and later, which implements proper HTML escaping or sanitization of the description field.

## Affected products

- Swagger swagger-ui before 2.2.1

## Timeline

- 2020-09-11: disclosed
- 2020-09-11: patched: Version 2.2.1 released

## References

- [https://github.com/swagger-api/swagger-ui/issues/830](https://github.com/swagger-api/swagger-ui/issues/830)
- [https://github.com/swagger-api/swagger-ui](https://github.com/swagger-api/swagger-ui)

## 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 Swagger UI Cross-Site Scripting in API response rendering](https://junglewise.ai/threats/swagger-swagger-ui-cross-site-scripting-in-api-response-rendering-be1bf724)
- [Swagger UI Cross-Site Scripting in method descriptions](https://junglewise.ai/threats/swagger-ui-cross-site-scripting-in-method-descriptions-d34bf589)
