The vulnerability is a classic stored Cross-Site Scripting (XSS) issue within the fabric.js library. The root cause is the failure to properly sanitize and escape user-controlled data when exporting a canvas to an SVG format. The primary attack vector starts with the StaticCanvas.loadFromJSON function, which deserializes a JSON object to populate a canvas. This function does not validate or sanitize the incoming data, allowing an attacker to insert malicious strings into various properties of fabric.js objects, such as id, image sources (src), and other attributes.
The actual vulnerability is triggered when the toSVG method (or a related SVG export method like getSvgCommons) is called on the objects. These methods would then interpolate the malicious strings directly into the resulting SVG markup without proper escaping. This allows the attacker's payload to break out of the intended attribute context and inject arbitrary SVG or HTML elements, including <script> tags or event handlers (e.g., onload, onbegin), which execute in the context of the user's browser.
The provided patch addresses this by applying an escapeXml function to all user-controllable properties before they are embedded in the SVG output. The analysis identified the key functions where this lack of escaping occurred, which are the primary vulnerable functions. The loadFromJSON function is also included as it represents the entry point for the malicious data.