Summary
A reflected cross-site scripting (XSS) vulnerability in SiYuan's dynamic icon API allows attacker-controlled content to be injected into SVG output without proper escaping when type=8 is used.
Because the endpoint is unauthenticated and returns image/svg+xml, a crafted URL can execute JavaScript in the SiYuan web origin when visited by a logged-in user, enabling unauthorized API actions and data exfiltration.
Affected context
The vulnerability occurs in SiYuan's web interface, specifically in the GET /api/icon/getDynamicIcon endpoint when called with type=8.
In affected versions, user-supplied input is embedded directly into SVG content and returned as image/svg+xml without proper escaping or sanitization.
The risk is realized when a victim—typically an authenticated SiYuan user—visits a specially crafted URL that triggers the vulnerable endpoint in a browser context where the response is executed within the SiYuan origin.
Exploit preconditions
- Attack surface: Public web endpoint
GET /api/icon/getDynamicIconon a SiYuan instance. - Required access: None; the endpoint is unauthenticated, so any external attacker can generate malicious URLs.
- Victim interaction: A logged-in SiYuan user must open or be redirected to the crafted URL in a browser (e.g., via email, chat, or embedded link).
- Trigger point: The browser loads the SVG from the vulnerable endpoint and interprets embedded event handlers or scripts in the context of the SiYuan web origin.
- Why exploitation is possible: Attacker-controlled data is injected into the SVG output without HTML/SVG escaping or content sanitization, enabling execution of active content such as
onerroror other event attributes.
Why this happens
This issue stems from improper neutralization of input before it is included in web content, mapping directly to CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-Site Scripting).
The dynamic icon endpoint accepts parameters that influence the generated SVG but fails to:
- encode or escape attacker-controlled segments before embedding them in the SVG DOM, and
- restrict or sanitize dangerous SVG/HTML constructs such as event handlers.
As a result, crafted input can break out of the intended data context and inject executable markup, causing the browser to execute attacker-supplied JavaScript under the SiYuan origin.
Potential impact
- Hijacking of active user sessions in the browser via authenticated API calls.
- Unauthorized actions on behalf of the victim (creating, modifying, or deleting notes and documents).
- Exfiltration of sensitive data stored in SiYuan, including personal notes and workspace metadata.
- Installation of persistent XSS or other malicious state (e.g., changing settings or injecting malicious content elsewhere).
- Pivoting to other applications in the same browser context via social engineering or additional vulnerabilities.
General mitigation guidance
Effective mitigation centers on eliminating the ability for user-controlled data to be interpreted as executable SVG/HTML:
- Apply strict context-aware output encoding for all parameters inserted into SVG attributes or text nodes so that attacker input is treated as data, not markup.
- Introduce server-side sanitization for dynamic icon parameters, rejecting or stripping event handlers, script-like constructs, and unexpected tags or attributes.
- Consider whitelisting only known-safe parameter values and icon formats instead of relying on blacklist rules.
- Where possible, separate data from presentation, using IDs or references to predefined SVG templates instead of emitting raw, user-influenced SVG markup.
- Implement defense-in-depth controls such as restrictive Content Security Policy (CSP) to reduce the impact of any remaining XSS vectors, while not relying on CSP as the sole fix.
How teams detect issues like this
Organizations can detect and prevent similar vulnerabilities through a combination of testing and code review practices:
- Use static analysis or linters configured with rules that flag direct concatenation of request parameters into HTML/SVG responses without encoding.
- In code review, look for endpoints that generate SVG or other rich markup from user input and verify they use safe encoding utilities and input validation.
- Incorporate dynamic application security testing (DAST) and script-based fuzzing focused on SVG,
<img>, and other media endpoints to identify XSS sinks. - Add security gates in CI/CD pipelines that automatically scan for XSS patterns and enforce policies (e.g., mandatory encoding helpers for view/template layers).

