/

CVE-2026-27013

Severity:

HIGH RISK

(7.6)

Cross-Site Scripting (XSS) in Fabric.js JSON-to-SVG Export

CVE-2026-27013

Analyzed

Vulnerability type

Category:

Cross-Site Scripting (XSS)

CWE:

CWE-79, CWE-116

Impact:

Stored Cross-Site Scripting in browser contexts rendering exported SVG

Severity:

HIGH RISK

(7.6)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

Fabric.js incorrectly escapes only text content, not all user-controlled attributes, when exporting canvas objects to SVG via toSVG().

If attacker-controlled JSON is loaded with loadFromJSON() and its SVG export is rendered in a browser, unescaped attribute values can inject arbitrary SVG markup and event handlers, leading to stored cross-site scripting (XSS) and execution of attacker-controlled JavaScript in the victim's session.

Affected context

The vulnerability arises in applications that use Fabric.js to:

  • Accept or persist user-supplied JSON (e.g., design documents, collaborative canvases, CMS content, templates) via loadFromJSON()
  • Export that canvas content to SVG via toSVG()
  • Render the resulting SVG in a browser context (inline <svg>, <img> with SVG, <object>, or similar)

The issue is specifically in the SVG export path where Fabric.js calls escapeXml() on text nodes but interpolates other user-controlled strings (e.g., style, IDs, data attributes, some properties) directly into SVG attributes without proper XML/HTML attribute escaping.

Exploit preconditions

  • Attack surface: Web applications using Fabric.js that:
  • Import or reconstruct canvases from JSON (loadFromJSON())
  • Subsequently generate SVG using toSVG()
  • Render the generated SVG within a page or any browser context that executes SVG/JS
  • Required access: Ability for an attacker to supply or influence the JSON content:
  • Direct JSON upload/import
  • Collaborative editing or sharing features
  • CMS/plugin integrations that store Fabric.js scene data
  • Trigger point: A victim's browser loads and renders the SVG output generated from the attacker-controlled JSON. This may happen in:
  • In-app SVG preview components
  • Embedded SVG exports in web pages or emails
  • Any workflow where the SVG is injected into the DOM
  • Why exploitation is possible: Not all user-controlled fields are passed through escapeXml() or an equivalent attribute-safe escaping routine. As a result, specially crafted attribute values can close existing attributes and inject arbitrary SVG elements, including those containing JavaScript event handlers or script execution constructs, which the browser then executes in the context of the application's origin.

Why this happens

The core issue is incomplete output encoding when converting internal object state to SVG markup. Fabric.js correctly applies escapeXml() to text content in one code path but fails to enforce consistent escaping for other string properties that end up as XML attributes.

This maps primarily to CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-site Scripting), because user-controlled data is embedded into a browser-interpreted document (SVG) without proper neutralization. It is also related to CWE-116: Improper Encoding or Escaping of Output, since the framework does not uniformly encode all outbound data for the specific context (XML attributes within SVG). The insecure pattern is treating some strings as "data" and others as "safe" while interpolating all of them into executable document contexts without a central, context-aware escaping layer.

Potential impact

  • Execution of arbitrary JavaScript in the victim's browser session
  • Theft of session tokens, CSRF tokens, or other sensitive data accessible via DOM or JavaScript APIs
  • Unauthorized actions in the victim's account by leveraging their authenticated session (e.g., modifying designs, altering content, exfiltrating documents)
  • Defacement or content injection within design canvases, previews, or exported artifacts
  • Lateral movement into integrated systems (e.g., CMS, billing, admin panels) if they share the same origin or trust the affected application

General mitigation guidance

Effective mitigation focuses on robust, context-aware output encoding and constraining what data flows into SVG and similar rich markup formats:

  • Centralize SVG serialization: Implement a single, well-reviewed serialization layer that is responsible for all string interpolation into SVG markup, ensuring it always applies appropriate XML/HTML attribute escaping for every user-controlled field.
  • Use context-aware escaping: Apply escaping routines designed for XML/HTML attribute contexts, not just text content. All dynamic attribute values (IDs, classes, styles, data attributes, transform strings, etc.) should be treated as untrusted and encoded before insertion.
  • Constrain allowed properties: Limit the set of object properties that can be serialized from user-controlled JSON into SVG attributes. Consider an allowlist of safe attributes and drop or sanitize everything else.
  • Normalize and validate input models: When loading JSON via loadFromJSON(), validate that string fields conform to expected patterns (e.g., no <, >, ", or event-style attribute fragments) and reject or sanitize data that fails validation.
  • Treat SVG as active content: When rendering exported SVG from untrusted sources, prefer sandboxed contexts (e.g., sanitized re-serialization, restrictive iframe sandboxes) and avoid directly injecting raw SVG into the main DOM whenever practical.
  • Apply least-privilege to frontend features: Design sensitive operations (e.g., account changes, administration, data exports) to require explicit user interaction and server-side validation, so that even if script execution occurs, the blast radius is reduced.

How teams detect issues like this

Detection typically combines static analysis, review practices, and runtime inspection:

  • Static analysis patterns:
  • Search for direct string concatenation into SVG/XML/HTML attributes, especially in export or serialization code paths (toSVG(), template generators, markup builders).
  • Flag uses of escaping functions that are limited to text nodes but not systematically applied to all attributes or contexts.
  • Code review signals:
  • Custom serialization logic that builds SVG strings manually instead of using robust, tested utilities.
  • Separate escape paths for "text" vs "attributes," or comments indicating assumptions that certain fields are safe without explicit sanitization.
  • Handling of user-controlled JSON or design documents that later influence any markup.
  • Policy enforcement:
  • Establish engineering guidelines that require context-aware escaping for any data inserted into SVG, HTML, or similar document formats.
  • Integrate secure coding checks into CI/CD pipelines to detect unescaped dynamic content in templates or export functions.
  • Assisted tooling:
  • Use automated code scanning tools configured with custom rules to detect unescaped interpolation into <svg> content and event-bearing attributes.

Sources

SourceLink
github.comgithub.com/fabricjs/fabric.js/commit/7e1a122defd8feefe4eb7eaf0c180d7b0aeb6fee
github.comgithub.com/fabricjs/fabric.js/releases/tag/v720
github.comgithub.com/fabricjs/fabric.js/security/advisories/GHSA-hfvx-25r5-qc3w

Frequently asked

questions

Yes. If an application exposes features that allow remote users to submit or share Fabric.js JSON content (e.g., via collaboration, uploads, or CMS integrations), an attacker can supply crafted JSON that results in malicious SVG markup. When another user or an administrator later views the SVG export in a browser, the injected script may execute.

The attacker needs the ability to influence the JSON input consumed by loadFromJSON(). This can range from full authenticated access to a design-editing feature, to more indirect paths like importing shared templates or content from external services. No direct access to the server is required; the vulnerability is triggered when the resulting SVG is rendered by a victim's browser.

The most robust fix is to implement strict, context-aware escaping for all user-controlled data before it is inserted into SVG or other markup, and to centralize serialization logic so that no attributes bypass this encoding. Complementary measures include limiting which properties can be serialized, validating input models, and treating all external or user-provided SVG-related data as untrusted.

Adopt a default stance that all outbound data is untrusted until it passes through a context-appropriate encoder. Incorporate secure coding practices for template generation and serialization, enforce code review checklists that explicitly consider XSS in SVG/HTML contexts, and use automated analysis tools to flag unsafe interpolation patterns. Additionally, design features so that handling of rich formats like SVG is minimized or sandboxed when dealing with data from untrusted sources.

Find out what's already
exploitable in your codebase.