/

CVE-2026-32940

Severity:

CRITICAL RISK

(9.3)

Cross-Site Scripting (XSS) in SiYuan Dynamic Icon API

CVE-2026-32940

Analyzed

Vulnerability type

Category:

Cross-Site Scripting (XSS)

CWE:

CWE-79, CWE-184

Impact:

Client-Side Code Execution / Session Compromise

Severity:

CRITICAL RISK

(9.3)

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

SiYuan versions 3.6.0 and below contain an SVG-based cross-site scripting (XSS) vulnerability where user-controlled content is injected into SVG markup and only partially sanitized.

By abusing overlooked data: MIME types in SVG links, an attacker can craft a URL that, when visited and clicked by a victim, leads to JavaScript execution in the victim's browser context.

Affected context

The vulnerability occurs in the unauthenticated /api/icon/getDynamicIcon endpoint, which generates SVG responses (Content-Type: image/svg+xml) from user-provided content parameters.

Affected deployments are those exposing this endpoint over HTTP(S) where:

  • The backend uses fmt.Sprintf (or equivalent string formatting) to interpolate user input into SVG without proper escaping.
  • SVG link sanitation relies on an incomplete blocklist that only denies certain data: MIME types (e.g., data:text/html, data:image/svg+xml) but not others capable of carrying script-enabled SVG (data:text/xml, data:application/xml).
  • Users can be induced to visit crafted URLs directly or via <object> / <embed> embedding, which preserves link interactivity inside SVGs.

Exploit preconditions

  • Attack surface: Publicly reachable /api/icon/getDynamicIcon endpoint.
  • Required access: None; an attacker can be unauthenticated and only needs the ability to send URLs to potential victims (e.g., via email, chat, or posting links).
  • Trigger point: A victim must:
  1. Load a crafted URL that calls /api/icon/getDynamicIcon with malicious content.
  2. Interact with (click) the rendered SVG link that uses a bypassed data: MIME type.
  • Why exploitation is possible:
  • User input is directly embedded into SVG markup via string formatting without HTML/SVG escaping.
  • The sanitization logic relies on a blocklist that omits certain XML-based data: MIME types, allowing SVG documents with executable JavaScript to be embedded in link targets.
  • The endpoint serves the response as image/svg+xml, enabling browsers to treat the result as interactive SVG when rendered via navigation or embed contexts.

Why this happens

The issue stems from combining unescaped output encoding with a blocklist-based sanitizer that does not fully account for all script-capable data: MIME types.

User-controlled data is placed into SVG attributes using fmt.Sprintf without proper encoding, which aligns with CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-site Scripting).

The sanitizer attempts to block some dangerous URL schemes (like data:text/html and data:image/svg+xml) but overlooks functionally equivalent schemes (data:text/xml, data:application/xml), mapping to CWE-184: Incomplete Blacklist.

This pattern exemplifies how relying on incomplete deny lists, especially for complex media types like SVG, can still permit script execution in a browser context.

Potential impact

  • Execution of attacker-controlled JavaScript in the victim's browser.
  • Theft of session identifiers, CSRF tokens, or other sensitive data accessible to the page context.
  • Unauthorized actions performed on behalf of the victim within the SiYuan application (if the victim is authenticated).
  • Phishing-style UI redressing within the SVG viewport to trick users into sensitive interactions.
  • Pivoting to other client-side vulnerabilities or browser features for broader compromise.

General mitigation guidance

Effective mitigation generally focuses on output encoding, safer rendering contexts, and whitelist-based URL handling:

  • Apply strict HTML/SVG escaping for any user-controlled data inserted into markup, using context-aware encoders rather than raw string formatting.
  • Prefer allowlist-based URL validation for attributes like href and xlink:href, only permitting benign schemes such as https, http, or mailto, and rejecting data: and javascript: entirely for interactive links.
  • Reduce or avoid dynamic SVG generation where interactivity is not strictly required, or render untrusted SVG as inert images (e.g., rasterizing server-side or delivering as non-interactive content).
  • Separate trusted application logic from untrusted display data, ensuring that untrusted data cannot influence link targets, event handlers, or script-capable contexts.
  • Implement a defense-in-depth content security policy (CSP) where applicable, limiting inline scripts and dangerous URL schemes to reduce XSS impact.

How teams detect issues like this

Detecting this kind of vulnerability typically involves a combination of static and review-based approaches:

  • Static analysis patterns:
  • Flagging direct string formatting or concatenation (fmt.Sprintf, +, template literals) used to build SVG/HTML responses with untrusted input.
  • Identifying uses of data: or javascript: URLs in href, xlink:href, and similar attributes, particularly when values derive from request parameters.
  • Code review signals:
  • Custom sanitization or blocklist functions focused on URL schemes or MIME types instead of using robust, tested libraries.
  • Endpoints returning image/svg+xml or HTML that interpolate request parameters into markup without consistent encoding.
  • Policy enforcement:
  • Security linters or CI checks that enforce context-aware encoding helpers in any response-generating code paths.
  • Automated tooling that scans for risky attributes in templates and dynamic content generators.

Sources

SourceLink
github.comgithub.com/advisories/GHSA-6865-qjcf-286f
github.comgithub.com/siyuan-note/siyuan/commit/d01d561875d4f744e9f6232f1d4831e3642b8696
github.comgithub.com/siyuan-note/siyuan/releases/tag/v3.6.1
github.comgithub.com/siyuan-note/siyuan/security/advisories/GHSA-4mx9-3c2h-hwhg

Frequently asked

questions

Yes. If the SiYuan instance exposes the /api/icon/getDynamicIcon endpoint over the network, an unauthenticated attacker can craft a malicious URL and send it to victims, who only need to visit the link and click the injected SVG element for code execution.

No attacker authentication is required to generate the malicious SVG, but impact is higher when the victim is authenticated to the SiYuan application or related domains, since any actions performed by the injected script occur in the victim's authenticated browser session.

The most robust fix is to combine strict, context-aware output encoding for all user-controlled data in SVG/HTML with an allowlist-based URL policy that only permits safe schemes (e.g., https, http) in link attributes, avoiding reliance on partial blocklists.

Adopt a secure-by-default templating and encoding strategy, avoid manual string interpolation for markup, enforce allowlists for URL-bearing attributes, and integrate static analysis plus security-focused code review practices to catch unsafe patterns involving SVGs and rich media content.

Find out what's already
exploitable in your codebase.