Summary
SiYuan's Bazaar marketplace rendered unescaped Name and Version fields from plugin, theme, template, widget, and icon metadata directly into the Settings → Marketplace UI.
Malicious HTML in those fields could be executed in the user's browser when viewing the marketplace tab, enabling stored cross-site scripting in the application context.
Affected context
The vulnerability affects SiYuan installations that:
- Use the built-in Bazaar (community marketplace) feature
- Load package metadata from plugin.json, theme.json, template.json, widget.json, or icon.json
- Render marketplace entries in Settings → Marketplace using innerHTML
In this flow, the backend only HTML-escapes Author, DisplayName, and Description, while Name and Version are passed through as-is and interpolated into HTML template strings on the frontend.
Exploit preconditions
- Attack surface: SiYuan Marketplace UI rendered in the user's browser.
- Required access: Ability to publish or influence package metadata (e.g., Name or Version fields) that the Bazaar consumes; any compromised distribution channel for these JSON files may suffice.
- User interaction: A user must open or refresh the Settings → Marketplace tab so that the vulnerable entries are rendered.
- Trigger point: The frontend substitutes unescaped Name/Version into template strings and assigns them to
innerHTML, causing embedded HTML/JavaScript to be parsed and executed. - Why exploitation is possible: Inputs that control HTML content are not properly escaped or encoded before being placed in an HTML context, violating output encoding requirements for untrusted data.
Why this happens
The core issue is incomplete output encoding of untrusted data rendered into HTML.
On the backend, sanitizePackageDisplayStrings escapes Author, DisplayName, and Description but omits Name and Version, leaving those fields raw. On the frontend, the Bazaar code in app/src/config/bazaar.ts interpolates these raw fields into template literals (e.g., ${item.preferredName}, ${data.name}, v${data.version}) and assigns the resulting string directly to innerHTML. This combination matches CWE-79: Improper Neutralization of Input During Web Page Generation (Cross-site Scripting), and is related to CWE-116: Improper Encoding or Escaping of Output.
Abstractly, the insecure pattern is:
- Trusting metadata fields as display-only text
- Failing to apply context-aware output encoding (HTML-escaping) for all untrusted fields
- Injecting those fields into HTML using
innerHTMLinstead of safer, text-only DOM APIs.
Potential impact
- Execution of arbitrary JavaScript in the context of the SiYuan desktop or web UI.
- Theft or manipulation of in-app data accessible via the UI and its APIs.
- Unauthorized actions performed on behalf of the user within SiYuan (e.g., configuration changes, content modifications).
- Installation of additional malicious marketplace entries or alteration of marketplace views.
- Pivot to other attacks if the SiYuan environment exposes tokens, local files, or privileged integration endpoints to the UI.
General mitigation guidance
Effective mitigation centers on enforcing strict output encoding and safe rendering patterns for all marketplace metadata:
- Apply context-appropriate HTML escaping to every untrusted text field rendered in the marketplace, including Name and Version.
- Avoid
innerHTMLfor dynamic content that originates from untrusted or semi-trusted sources; instead, usetextContent, DOM APIs, or templating systems that encode output by default. - Centralize sanitization in a single helper that consistently covers all displayable fields, reducing the chance of omissions when new fields are added.
- Treat package metadata as untrusted input regardless of its apparent origin, and enforce a clear contract between backend sanitization and frontend rendering.
- Consider a "safe-by-default" UI layer where any raw HTML injection requires explicit opt-in and justification.
How teams detect issues like this
Organizations can detect similar issues through a combination of review and automation:
- Static analysis: Configure rules that flag assignments to
innerHTML,outerHTML, or similar sinks when they include dynamic data, especially from external JSON or network responses. - Code review: During frontend and API reviews, verify that all fields derived from package metadata or other remote sources are passed through an appropriate escaping or sanitization function before being rendered.
- Security testing: Perform focused XSS testing on marketplace-like views by injecting benign HTML/JavaScript in metadata fields in a staging environment to validate that they are rendered as text, not executed.
- Policy enforcement: Introduce coding guidelines that mandate context-aware output encoding and prefer safe DOM manipulation APIs over raw HTML string concatenation, enforced via linters or pre-commit hooks.

