The vulnerability is a stored Cross-Site Scripting (XSS) issue in the API Publisher portal of WSO2 API Manager. It stems from improper validation of documents uploaded for APIs and API Products. The root cause is that the application trusted the user-supplied Content-Type HTTP header and did not verify that the file's actual content matched its extension.
The analysis of the patch commit 1b3496c072ec68aaaf726996e2caa76f07c1adca reveals the exact functions involved. The exploitation flow starts at the REST API endpoints addAPIDocumentContent (for APIs) and addAPIProductDocumentContent (for API Products). These endpoints receive the file upload from a privileged user.
Prior to the patch, these endpoints called the utility functions attachFileToDocument and attachFileToProductDocument, respectively. These utility functions contained the flawed logic of determining the file's media type based on the Content-Type header. This allowed an attacker to upload a file with a seemingly safe extension (e.g., .txt) but with a Content-Type of text/html and malicious JavaScript payload inside. When another user viewed this document, the browser would render the HTML and execute the script.
The patch addresses this by introducing a new utility function, detectAndValidateMediaType, which uses the Apache Tika library to detect the MIME type from the file's byte content. It then ensures that the detected MIME type corresponds to the file's extension. This prevents the mismatch that allowed the XSS attack. The vulnerable functions are the API endpoints that accept the input and the utility functions that processed it without proper validation.