Summary
SiYuan's marketplace cards serialize untrusted package metadata directly into a data-obj HTML attribute without escaping, allowing injected markup when names contain single quotes.
In the desktop client, where nodeIntegration is enabled and contextIsolation is disabled, this DOM XSS can escalate to arbitrary OS command execution.
Affected context
The vulnerability occurs in SiYuan's marketplace UI when package fields such as name, version, author, and description are serialized into a data-obj attribute using JSON.stringify() without HTML escaping.
It is relevant in deployments where unreviewed or third-party packages can appear in the marketplace and the desktop client runs with nodeIntegration enabled and contextIsolation disabled, which turns script injection into an OS-level code execution risk.
Exploit preconditions
- Attack surface: SiYuan marketplace card rendering in the desktop application and any embedded browser context that reflects package metadata.
- Required access: Ability to publish or influence marketplace package metadata (e.g., package name) so that it is rendered by a user's client.
- Trigger point: User visits or refreshes the marketplace view where vulnerable cards are rendered and the crafted metadata is embedded into the data-obj attribute.
- Why exploitation is possible: Unescaped single quotes in JSON.stringify() output allow the attacker-controlled field to break out of the single-quoted HTML attribute and inject arbitrary HTML, which the browser interprets as part of the page DOM. In the desktop client configuration, injected scripts can access Node APIs and execute OS commands.
Why this happens
The underlying bug is a failure to apply proper output encoding to untrusted data before inserting it into HTML attributes, mapping directly to CWE-79 (Improper Neutralization of Input During Web Page Generation).
Using JSON.stringify() as a serialization helper does not provide HTML context-aware escaping, so characters like single quotes, angle brackets, and greater-than signs remain intact and can terminate attributes or start new HTML elements.
In the desktop Electron-based client, permissive settings such as nodeIntegration: true and contextIsolation: false further extend the impact from client-side script injection to CWE-94-style arbitrary code execution, because injected scripts can interact with Node.js and the underlying operating system.
Potential impact
- Attackers may inject arbitrary HTML and JavaScript into the marketplace view.
- Malicious scripts could execute OS commands via Node.js APIs in the desktop client.
- Users' local data and files can be read, modified, or exfiltrated by injected code.
- The application's integrity may be compromised, enabling further persistence or payload delivery.
- Attackers could impersonate UI elements, phish credentials, or mislead users within the app.
General mitigation guidance
Mitigation centers on treating all marketplace metadata as untrusted and applying strict context-aware output encoding before inserting values into HTML attributes or the DOM.
Common defensive patterns include:
- Encoding special characters for HTML and attribute contexts (e.g., escaping quotes, angle brackets, and ampersands) before serialization.
- Avoiding direct string concatenation for building HTML; instead, use safe DOM APIs that separate data from markup.
- Reducing the privileges of browser environments by disabling nodeIntegration and enabling contextIsolation to prevent script access to OS-level capabilities.
- Applying least-privilege principles for any bridge APIs exposed to renderer processes, ensuring that even if script injection occurs, sensitive operations remain inaccessible.
- Treating marketplace content as external input and layering validation, sanitization, and policy checks on submission and rendering.
How teams detect issues like this
Effective detection strategies focus on identifying unescaped user-controlled data in HTML generation paths and overly permissive runtime configurations.
Approaches may include:
- Static analysis rules that flag direct interpolation of untrusted variables into HTML attributes or innerHTML without context-aware encoding.
- Code review practices that scrutinize any uses of JSON.stringify() or template literals in UI rendering, especially when combined with single-quoted attributes.
- Configuration audits of Electron or webview-based clients to detect nodeIntegration: true, contextIsolation: false, or similar high-risk settings.
- Automated security testing (e.g., DOM XSS probes) against marketplace views to detect reflection of crafted metadata in the rendered DOM.
- Policy enforcement in CI that requires safe encoding utilities and rejects patterns known to lead to XSS in templating or front-end code.

