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/getDynamicIconendpoint. - 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:
- Load a crafted URL that calls
/api/icon/getDynamicIconwith maliciouscontent. - 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
hrefandxlink:href, only permitting benign schemes such ashttps,http, ormailto, and rejectingdata:andjavascript: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:orjavascript:URLs inhref,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+xmlor 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.

