GHSA-68p4-j234-43mv: SiYuan is Vulnerable to Cross-Origin RCE via Permissive CORS Policy and JavaScript Snippet Injection
SummaryA malicious website can achieve Remote Code Execution (RCE) on any desktop running SiYuan by exploiting the permissive CORS policy (`Access-Control-Allow-Origin: *` + `Access-Control-Allow-Private-Network: true`) to inject a JavaScript snippet via the API. The injected snippet executes in Electron's Node.js context with full OS access the next time the user opens SiYuan's UI. No user interaction is required beyond visiting the malicious website while SiYuan is running.Details**Vulnerable files:**`kernel/server/serve.go`, lines 960-963 — CORS middleware`kernel/api/snippet.go`, lines 93-128 — snippet injection endpoint**Root cause:** The CORS middleware unconditionally sets:The `Access-Control-Allow-Private-Network: true` header explicitly opts into Chrome's Private Network Access specification, telling the browser that external websites are permitted to access this localhost service. Combined with `Access-Control-Allow-Origin: *`, any website on the internet can make authenticated cross-origin requests to the SiYuan API at `127.0.0.1:6806`.The auth middleware at `kernel/model/session.go:251-280` checks the `Origin` header, but this check is bypassed because the browser sends the session cookie (set on `127.0.0.1`) along with the cross-origin request, and the server validates the cookie before reaching the Origin check for unauthenticated sessions.**Attack chain:**User visits `https://evil-attacker.com` while SiYuan desktop is runningMalicious JS sends CORS preflight to `http://127.0.0.1:6806` — SiYuan responds with permissive CORS headersBrowser sends actual POST to `/api/snippet/setSnippet` with the user's session cookieSiYuan accepts the request and saves a malicious JS snippetThe snippet executes in Electron's renderer process with Node.js integration, achieving arbitrary code executionPoC**Malicious webpage (hosted on any domain):****Verification steps:**Start SiYuan desktop (or Docker with `SIYUAN_ACCESS_AUTH_CODE` set)Login to SiYuan in a browser to establish a session cookieIn the same browser, navigate to the malicious pageVerify snippet was injected:**Tested and confirmed on SiYuan v3.6.1 (Docker).** The CORS preflight returns permissive headers, the snippet is injected from `Origin: https://evil-attacker.com`, and the API token is exfiltrated — all in a single page load.Impact**Remote Code Execution:** Any website can execute arbitrary OS commands on the user's machine via Electron's Node.js integration. The attacker gains full control with the user's privileges.**Data exfiltration:** The attacker can read all notes, configuration (including API tokens), and workspace data via the API before the RCE payload even triggers.**No user interaction beyond browsing:** The victim only needs to visit a malicious/compromised webpage while SiYuan is running. No clicks, no downloads, no permissions dialogs.**Affects all desktop users:** SiYuan desktop runs on `127.0.0.1:6806` by default. The `Access-Control-Allow-Private-Network: true` header explicitly bypasses Chrome's Private Network Access protection that would otherwise block this attack.**Persistence:** The injected JS snippet is saved to disk and executes every time SiYuan loads, surviving restarts.
CVSS v3.1: 9.6