The vulnerability is a stored Cross-Site Scripting (XSS) issue in HAXcms. The root cause is the saveFile function, which allows authenticated users to upload arbitrary files, including HTML files containing malicious JavaScript. The application fails to prevent these uploaded HTML files from being rendered directly in a user's browser.
The exploit unfolds in two stages:
- Storing the Payload: The attacker uploads an HTML file containing a malicious script using the
/system/api/saveFile endpoint, which is handled by the saveFile function.
- Executing the Payload: A victim (typically an administrator) is tricked into navigating to the URL of the uploaded file. The browser renders the HTML and executes the script.
The script in the provided PoC targets the /system/api/refreshAccessToken endpoint. When executed with the administrator's session cookies, the refreshAccessToken function returns a new JWT, which the script then exfiltrates to an attacker-controlled server, leading to account takeover.
The patch mitigates the vulnerability not by changing the saveFile or refreshAccessToken functions, but by introducing a new middleware in src/app.js. This middleware intercepts requests for HTML files within the /files/ directory and adds a Content-Disposition: attachment header, forcing the browser to download the file instead of rendering it, thus preventing the XSS from executing.