An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:lock: Prevent stored XSS via notebook name in the daily note picker https://github.com/siyuan-note/siyuan/security/advisories/GHSA-8c2m-33v9-vvqm
Danielf7cdadc21e6b
diff --git a/app/src/util/dailyNote.test.ts b/app/src/util/dailyNote.test.tsindex 9712f27a51..5e90ae0a74 100644--- a/app/src/util/dailyNote.test.ts+++ b/app/src/util/dailyNote.test.ts@@ -1,6 +1,6 @@import {describe, it} from "node:test";import * as assert from "node:assert/strict";-import {getLastDailyNoteNotebookId} from "./dailyNote";+import {genNotebookOptionsHTML, getLastDailyNoteNotebookId} from "./dailyNote";describe("daily note notebook selection", () => {const notebooks = [@@ -18,3 +18,35 @@ describe("daily note notebook selection", () => {assert.equal(getLastDailyNoteNotebookId(notebooks, undefined), undefined);});});++describe("daily note notebook options", () => {+ it("escapes notebook names so they cannot inject markup", () => {+ const html = genNotebookOptionsHTML([{+ id: "20260101120000-abcdefg",+ name: "</option></select><img src=x onerror=alert(document.domain)>",+ closed: false,+ }]);+ assert.ok(!html.includes("<img"), `raw img tag reached dialog HTML: ${html}`);+ // escapeHtml 只处理 & 和 <,转义 < 已足以让标签无法成立+ assert.ok(html.includes("</option></select><img src=x onerror=alert(document.domain)>"),+ `actual: ${JSON.stringify(html)}`);+ });++ it("escapes ampersands so stored entities stay text", () => {+ const html = genNotebookOptionsHTML([{+ id: "20260101120000-abcdefg",+ name: "<img src=x onerror=alert(document.domain)>",+ closed: false,+ }]);+ assert.ok(!html.includes("<img"), `entity decoded into a live tag: ${html}`);+ assert.ok(html.includes("&lt;img"), `actual: ${JSON.stringify(html)}`);+ });++ it("skips closed notebooks and keeps plain names unchanged", () => {+ const html = genNotebookOptionsHTML([+ {id: "20260101120000-abcdefg", name: "Notes & Ideas", closed: false},+ {id: "20260101120001-hijklmn", name: "Closed", closed: true},+ ]);+ assert.equal(html, "<option value=\"20260101120000-abcdefg\">Notes & Ideas</option>");+ });+});diff --git a/app/src/util/dailyNote.ts b/app/src/util/dailyNote.tsindex 90f6e921e4..767d32f2cb 100644--- a/app/src/util/dailyNote.ts+++ b/app/src/util/dailyNote.ts@@ -1,3 +1,17 @@+import {escapeAttr, escapeHtml} from "./escape";++// 笔记本名不做 HTML 过滤,拼接到对话框 HTML 前必须转义,否则名称中的标签会注入执行+// https://github.com/siyuan-note/siyuan/security/advisories/GHSA-8c2m-33v9-vvqm+export const genNotebookOptionsHTML = (notebooks: readonly {id: string, name: string, closed: boolean}[]) => {+ let optionsHTML = "";+ notebooks.forEach(item => {+ if (!item.closed) {+ optionsHTML += `<option value="${escapeAttr(item.id)}">${escapeHtml(item.name)}</option>`;+ }+ });+ return optionsHTML;+};+export const getLastDailyNoteNotebookId = (notebooks: readonly {id: string, closed: boolean}[],storedNotebookId: unknown,diff --git a/app/src/util/mount.ts b/app/src/util/mount.tsindex e1e3b4ab3c..7cb21010f3 100644--- a/app/src/util/mount.ts+++ b/app/src/util/mount.ts@@ -12,7 +12,7 @@ import {setStorageVal} from "../protyle/util/compatibility";import {openFileById} from "../editor/util";import {openMobileFileById} from "../mobile/editor";import type {App} from "../index";-import {getLastDailyNoteNotebookId} from "./dailyNote";+import {genNotebookOptionsHTML, getLastDailyNoteNotebookId} from "./dailyNote";import {getHostCapabilities} from "./hostCapabilities";/// #if !BROWSERimport {ipcRenderer} from "electron";@@ -66,12 +66,7 @@ const openDailyNote = (app: App, useLastNotebook: boolean) => {if (lastNotebookId && useLastNotebook) {fetchNewDailyNote(app, lastNotebookId);} else {- let optionsHTML = "";- window.siyuan.notebooks.forEach(item => {- if (!item.closed) {- optionsHTML += `<option value="${item.id}">${item.name}</option>`;- }- });+ const optionsHTML = genNotebookOptionsHTML(window.siyuan.notebooks);const dialog = new Dialog({positionId: Constants.DIALOG_DIALYNOTE,title: window.siyuan.languages.plsChoose,