An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Use OIDC sessions for encrypted notebook system locking https://github.com/siyuan-note/siyuan/issues/20417
Daniel11dfd86873c9
diff --git a/app/electron/notebookSystemLock.js b/app/electron/notebookSystemLock.jsindex 40b397894d..eed5fb8e41 100644--- a/app/electron/notebookSystemLock.js+++ b/app/electron/notebookSystemLock.js@@ -1,7 +1,7 @@const fs = require("node:fs/promises");const path = require("node:path");-// 主进程直接请求本地内核,窗口关闭或访问会话退出后仍可锁定,认证材料只从本地配置读取。+// 主进程直接请求本地内核,优先使用配置中的认证材料;仅会话认证时使用本地窗口的会话。const createNotebookSystemLock = ({getWorkspaces, fetch, writeLog, prepare = async () => {}, readFile = fs.readFile}) => {const pending = new Map();const running = new Map();@@ -35,7 +35,7 @@ const createNotebookSystemLock = ({getWorkspaces, fetch, writeLog, prepare = asymethod: "POST",headers,body: "{}",- credentials: "omit",+ credentials: headers.Authorization ? "omit" : "include",redirect: "error",signal: controller.signal,});diff --git a/app/electron/notebookSystemLock.test.js b/app/electron/notebookSystemLock.test.jsindex 8c25db7108..48be55d4f4 100644--- a/app/electron/notebookSystemLock.test.js+++ b/app/electron/notebookSystemLock.test.js@@ -10,6 +10,33 @@ const workspace = (port, ownsKernel = true) => ({});const config = JSON.stringify({system: {encryptedNotebookFollowSystemLock: true}, api: {token: "secret"}});+test("system lock uses the session when OIDC has no token or lock password", async () => {+ for (const credentials of [+ {api: {token: ""}, accessAuthCode: "", oidc: {enabled: true}},+ {api: {token: "secret"}},+ {api: {token: ""}, accessAuthCode: "password"},+ ]) {+ let requests = 0;+ const controller = createNotebookSystemLock({+ getWorkspaces: () => [workspace(6806)],+ readFile: async () => JSON.stringify({...credentials, system: {encryptedNotebookFollowSystemLock: true}}),+ fetch: async (_url, options) => {+ requests++;+ const authorization = credentials.api.token ? "Token secret" : credentials.accessAuthCode ?+ "Basic " + Buffer.from("workspace:password").toString("base64") : undefined;+ assert.equal(options.headers.Authorization, authorization);+ assert.equal(options.credentials, authorization ? "omit" : "include");+ assert.equal(options.redirect, "error");+ return {ok: true, json: async () => ({code: 0})};+ },+ writeLog: assert.fail,+ });+ await controller.lock();+ await controller.retry();+ assert.equal(requests, 1);+ }+});+test("system lock submits pending edits before authenticated local requests without renderer windows", async () => {const events = [];const controller = createNotebookSystemLock({