From 32eb027c7cf0c5788c53f45444827a604727d460 Mon Sep 17 00:00:00 2001 From: priv <140729444+scriptprivate@users.noreply.github.com> Date: Thu, 7 Nov 2024 08:58:36 -0300 Subject: [PATCH] feat(blog): add English version of CVE-2016-1000226 post --- .../2024-11-07-CVE-2016-1000226-EN.markdown | 166 ++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 _posts/2024-11-07-CVE-2016-1000226-EN.markdown diff --git a/_posts/2024-11-07-CVE-2016-1000226-EN.markdown b/_posts/2024-11-07-CVE-2016-1000226-EN.markdown new file mode 100644 index 000000000..2eee9ed2c --- /dev/null +++ b/_posts/2024-11-07-CVE-2016-1000226-EN.markdown @@ -0,0 +1,166 @@ +--- +layout: post +title: "Analysis of CVE-2016-1000226: XSS in Swagger-UI" +date: 2024-11-07 +--- + +[CVE-2016-1000226](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2016-1000226)\[1\] is a [cross-site scripting (XSS)](https://portswigger.net/web-security/cross-site-scripting)\[2\] vulnerability in [Swagger-UI](https://swagger.io/tools/swagger-ui/)\[3\], disclosed on July 21, 2016, affecting versions prior to **2.2.2**. This vulnerability allows an attacker to inject malicious scripts into API input parameters and within its Swagger JSON document generation. + +This publication is also available in: [Portugues](https://blog.lesis.lat/blog/CVE-2016-1000226/) + +--- + +**What is Swagger-UI?** + +Swagger-UI is an open-source tool that displays API specifications in a developer-friendly graphical interface. Widely used for managing, documenting, and testing APIs, it allows easy visualization and interaction with RESTful APIs directly in the browser. + +This tool operates based on the Swagger document, which describes the API, using a JavaScript library to process and render the content graphically on the screen. + +--- + +**Vulnerability** + +Although the Swagger-UI has a significant history of XSS vulnerabilities, all previous vulnerabilities required user interaction for a successful exploitation. The current vulnerability, however, is a DOM XSS that does not require such interaction. Since the vulnerability is controlled by query parameters, an attacker can exploit it without any user involvement. + +This flaw arises from Swagger-UI’s use of an outdated version of the [DOMPurify](https://github.com/cure53/DOMPurify)\[4\] library in versions prior to 2.2.2, which prevents proper sanitization of user-provided input parameters. + +--- + +**How does Swagger UI render API specifications?** + +The process begins with creating a Swagger document (OpenAPI Specification), that defines the API structure, including endpoints, methods, parameters, and other relevant information about the API. This document is typically written in YAML or JSON format. + +Then, when accessing Swagger-UI in the browser and providing the URL or file containing the Swagger document, the interface starts the document loading process. This can be done either through the API URL where the Swagger document is hosted or by directly uploading the file. + +Let's focus on the function that enables loading a Swagger document via a URL, which can be done in two ways: + +* ?url=https://host/spec.yaml +* ?configUrl=https://host/file.json + +Next, Swagger fetches the JSON configuration or YAML API specifications, processes them, and renders the content in the user's browser. Additionally, it interprets any description fields in the API specification as [Markdown](https://pt.wikipedia.org/wiki/Markdown)\[5\]. + +Example of how [YAML](https://pt.wikipedia.org/wiki/YAML)\[6\] specifications are structured: + +```yml +swagger: '2.0' + info: + title: Example yaml.spec + description: This is an example text \*\*HELLO FROM MARKDOWN\*\* + paths: + /accounts: + get: + responses: + '200': + description: No response was specified + tags: + \- accounts + operationId: findAccounts + summary: Finds all accounts +``` + +Helper function used to render *Markdown* in the Swagger UI: + +// src/components/providers/markdown.jsx +```javascript + function Markdown({ source, className \= "", getConfigs }) { + ... omitted ... + + const md \= new Remarkable({ + html: true, + typographer: true, + breaks: true, + linkTarget: "\_blank" + }).use(linkify) + + md.core.ruler.disable(\["replacements", "smartquotes"\]) + + const { useUnsafeMarkdown } \= getConfigs() + const html \= md.render(source) + const sanitized \= sanitizer(html, { useUnsafeMarkdown }) + + if (\!source || \!html || \!sanitized) { + return null + } + + return ( + \