Summary
SiYuan's Bazaar README renderer mishandles HTML sanitization, allowing modern inline event handlers in Markdown to pass through and execute as JavaScript in the Administrator's browser.
When an Administrator views a malicious package README in the Marketplace, the attacker's code can run in the authenticated SiYuan origin and potentially take full control of the workspace.
Affected context
The vulnerability occurs in SiYuan's Marketplace (Bazaar) package viewing flow where README files are rendered from Markdown to HTML.
It is relevant in deployments where:
- Administrators browse third-party packages via Settings → Marketplace
- README content from packages is treated as trusted Markdown
- Server-side sanitization relies solely on a legacy event-handler blocklist
- The rendered HTML is injected into the main document without an additional client-side sanitizer or sandboxing
Exploit preconditions
- Attack surface: Bazaar Marketplace README rendering in the SiYuan web UI.
- Required access: Ability to publish or control the content of a Bazaar package README that an Administrator can view; no direct access to the victim's instance is required beyond normal Marketplace exposure.
- Trigger point: An Administrator opens a malicious package in Settings → Marketplace, causing the README to be rendered and its HTML assigned to
innerHTMLin the main document, then interacts with the page so the bound events fire. - Why exploitation is possible: The lute sanitizer uses a fixed event-handler blocklist copied from a legacy list and does not recognize modern event attributes such as
onpointerover,onpointerdown,onauxclick,onbeforetoggle,onfocusin,onanimationstart, andontransitionend. These attributes are preserved verbatim and, since the HTML is injected without CSP or iframe sandboxing, inline handlers execute in the Administrator's browser context.
Why this happens
The underlying bug is incomplete HTML sanitization stemming from a fragile, allowlist/blocklist approach to event attributes.
In the renderPackageREADME path, Markdown is converted to HTML with the lute engine and SetSanitize(true), but the sanitizer's allowAttr function only rejects attribute names found in a static eventAttrs map derived from an outdated w3schools handler list.
Modern DOM event handler attributes are simply not included in that map, so they bypass filtering entirely and are delivered to the client unchanged.
On the frontend, this HTML is directly assigned to mdElement.innerHTML without additional sanitization or isolation, mapping to CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-Site Scripting) and CWE-184: Incomplete List of Disallowed Inputs, where partial blocklists create gaps that attackers can exploit.
Potential impact
- An attacker may execute arbitrary JavaScript in the Administrator's browser session.
- Malicious code could manipulate or exfiltrate workspace content, notes, and configurations.
- The attacker can potentially perform administrative actions on behalf of the Administrator.
- Session cookies or tokens accessible to frontend scripts could be stolen or abused.
- The SiYuan instance can be driven into an unsafe state, including data corruption or unauthorized configuration changes.
General mitigation guidance
Effective mitigation focuses on robust HTML sanitization and minimizing trust in remote package content.
Common defensive patterns include:
- Replacing ad-hoc event-handler blocklists with well-maintained, security-focused sanitization libraries that enforce strict HTML and attribute allowlists.
- Treating remote Markdown and README content as untrusted input and sanitizing it with context-aware rules before inserting it into the DOM.
- Avoiding direct
innerHTMLassignments for untrusted content; instead, render through templating systems or APIs that strip scriptable constructs by default. - Applying least-privilege principles to the administrative UI by limiting what untrusted content can access, and considering rendering risky content in sandboxed iframes where feasible.
- Leveraging browser security headers (e.g., a restrictive Content Security Policy, X-Frame-Options, X-Content-Type-Options) to reduce the impact of any remaining script injection vectors.
How teams detect issues like this
Detection typically involves a combination of code-level and behavioral analysis:
- Static analysis rules that flag use of
innerHTMLor similar DOM injection APIs with data derived from external or package-controlled sources. - Code review practices that look for custom sanitizers relying on blocklists or incomplete event/attribute filters, especially those based on legacy lists.
- Automated security testing of the README rendering pipeline with fuzzed or crafted Markdown containing modern event handlers and script-like constructs.
- Policy enforcement in CI/CD that requires any HTML sanitization logic to be backed by vetted libraries and prohibits bypassing centralized sanitization routines.
- Application-level monitoring that logs and alerts on unexpected script executions or anomalous administrative actions following Marketplace interactions.

