The vulnerability is a stored Cross-Site Scripting (XSS) issue that occurs when an authenticated user uploads a malicious SVG file and creates a hotlink for it. The root cause is the application's failure to properly validate the Content-Type of uploaded files.
The analysis of the commits between the vulnerable version 2.2.2 and the patched version 2.2.3 reveals the vulnerable code, although the specific fixing commit is not immediately obvious from the commit messages.
The primary vulnerable function is chunking.parseContentType located in internal/storage/chunking/Chunking.go. This function determines the Content-Type for a new file. As seen in the code, it trustfully accepts the filecontenttype parameter from the user's request. An attacker can set this to image/svg+xml for an uploaded SVG file containing malicious JavaScript. This Content-Type is then stored in the database associated with the file.
The second function involved is the one that handles serving the hotlinked files. While the exact function name is not present in the provided diffs, it is the component that reads the stored Content-Type from the database and uses it to set the Content-Type HTTP header in the response. When a user visits the hotlink, the browser receives the Content-Type: image/svg+xml header and proceeds to render the SVG, executing the embedded script.
The function models.getHotlinkUrl in internal/models/FileList.go is also relevant as it is responsible for generating the hotlink URL that a victim would click on to trigger the payload. Changes to this function were present in the commits analyzed.
In summary, the exploit chain is as follows:
- An attacker uploads an SVG file with a malicious script.
- During the upload, the
chunking.parseContentType function reads the attacker-supplied Content-Type of image/svg+xml and stores it.
- The attacker creates a hotlink to the file using a URL generated by
models.getHotlinkUrl.
- A victim accesses the hotlink, causing the server to serve the SVG file with the malicious
Content-Type, leading to XSS.