Summary
ThingsBoard in versions prior to v4.2.1 allows an authenticated user to upload malicious SVG images via the “Image Gallery”, leading to a Stored Cross-Site Scripting (XSS) vulnerability. The exploit can be triggered when any user accesses the public API endpoint of the malicious SVG images, or if the malicious images are embedded in an iframe element, during a widget creation, deployed to any page of the platform (e.g., dashboards), and accessed during normal operations. The vulnerability resides in the ImageController, which fails to restrict the execution of JavaScript code when an image is loaded by the user’s browser. This vulnerability can lead to the execution of malicious code in the context of other users’ sessions, potentially compromising their accounts and allowing unauthorized actions.
Product
This vulnerability affects ThingsBoard versions prior to v4.2.1.
Impact
This vulnerability can lead to the execution of malicious code in the context of other users’ sessions, potentially compromising their accounts and allowing unauthorized actions.
Steps to reproduce
-
Craft a simple payload to be injected into an SVG image that pops up a JavaScript alert:
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="0 0 200 200"> <!-- Visual SVG --> <rect width="200" height="200" fill="#3498db" /> <!-- Text in the center --> <text x="50%" y="50%" font-size="20" text-anchor="middle" dy=".3em" fill="white">Proof of Concept</text> <!-- XSS Payload: Pop up an alert box with the JWT --> <script type="text/javascript"> <![CDATA[ alert(JSON.stringify(localStorage)); ]]> </script> </svg> -
Login to ThingsBoard as a tenant administrator
-
Upload the SVG image using the Image Gallery
-
Copy the public image API endpoint for the malicious SVG image
-
Access the public image API endpoint
Expected result
The XSS payload is executed as soon as anyone accesses the malicious SVG image public API endpoint. It is also possible to embed the SVG image in an iframe by creating an widget, and deploying it to any page, like a dashboard. If a user during normal browsing opens the page with the malicious widget, the XSS payload will be executed.
Remediation
Fixed in ThingsBoard v4.2.1 by adding the Content-Security-Policy header with the default-src 'none' value. This prevents external resources (scripts, styles, frames, etc.) being loaded from uploaded files, including SVG images.
Credit
This issue was discovered and reported by Checkmarx Security Researcher João Oliveira.