Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Stop exposing the absolute workspace path to browsers https://github.com/siyuan-note/siyuan/issues/17410

Danielabe1fe19d566
diff --git a/app/src/util/processTitle.ts b/app/src/util/processTitle.ts
index 67f578768f..4a5709e978 100644
--- a/app/src/util/processTitle.ts
+++ b/app/src/util/processTitle.ts
@@ -3,7 +3,10 @@ import {Constants} from "../constants";
import {pathPosix} from "./pathName";
export const getWorkspaceName = () => {
- return pathPosix().basename(window.siyuan.config.system.workspaceDir.replace(/\\/g, "/"));
+ const dir = window.siyuan.config.system.workspaceDir;
+ // 浏览器环境下内核不返回工作空间绝对路径,回退到应用名以避免标题/顶栏出现空段
+ // https://github.com/siyuan-note/siyuan/issues/17410
+ return dir ? pathPosix().basename(dir.replace(/\\/g, "/")) : window.siyuan.languages.siyuanNote;
};
export const setTitle = (title: string, showVersionTitle = false) => {
diff --git a/kernel/api/system.go b/kernel/api/system.go
index 750185f63f..2e7c185d4f 100644
--- a/kernel/api/system.go
+++ b/kernel/api/system.go
@@ -574,6 +574,17 @@ func getConf(c *gin.Context) {
maskedConf = model.FilterConfByPublishIgnore(publishIgnore, maskedConf)
}
+ // 浏览器环境下不返回工作空间绝对路径,避免泄露用户名等敏感信息
+ // 原生客户端(桌面 Electron、移动端)UA 以 "SiYuan/" 开头,照常返回真实路径
+ // REF: https://github.com/siyuan-note/siyuan/issues/17410
+ if util.IsBrowserRequest(c) {
+ maskedConf.System.WorkspaceDir = ""
+ maskedConf.System.AppDir = ""
+ maskedConf.System.ConfDir = ""
+ maskedConf.System.DataDir = ""
+ maskedConf.System.HomeDir = ""
+ }
+
ret.Data = map[string]any{
"conf": maskedConf,
"start": !util.IsUILoaded,
diff --git a/kernel/server/serve.go b/kernel/server/serve.go
index acf641da2d..c4bd579bfa 100644
--- a/kernel/server/serve.go
+++ b/kernel/server/serve.go
@@ -597,10 +597,15 @@ func serveAuthPage(c *gin.Context) {
"appearanceMode": model.Conf.Appearance.Mode,
"appearanceModeOS": model.Conf.Appearance.ModeOS,
"workspace": util.WorkspaceName,
- "workspacePath": util.WorkspaceDir,
"keymapGeneralToggleWin": keymapHideWindow,
"trayMenuLangs": util.TrayMenuLangs[util.Lang],
- "workspaceDir": util.WorkspaceDir,
+ // 浏览器环境下不返回工作空间绝对路径,避免泄露用户名等敏感信息
+ // 原生客户端(桌面 Electron,授权页 siyuan-init IPC 仅在 Electron 内执行)照常返回真实路径
+ // REF: https://github.com/siyuan-note/siyuan/issues/17410
+ "workspaceDir": util.WorkspaceDir,
+ }
+ if util.IsBrowserRequest(c) {
+ model["workspaceDir"] = ""
}
buf := &bytes.Buffer{}
if err = tpl.Execute(buf, model); err != nil {
diff --git a/kernel/util/session.go b/kernel/util/session.go
index 32ff0b4454..f330c76c56 100644
--- a/kernel/util/session.go
+++ b/kernel/util/session.go
@@ -17,6 +17,8 @@
package util
import (
+ "strings"
+
"github.com/88250/gulu"
ginSessions "github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
@@ -93,3 +95,11 @@ func GetWorkspaceSession(session *SessionData) (ret *WorkspaceSession) {
func RemoveWorkspaceSession(session *SessionData) {
delete(session.Workspaces, WorkspaceDir)
}
+
+// IsBrowserRequest 判断请求是否来自浏览器(非 SiYuan 原生客户端)。
+// 原生客户端(桌面 Electron、Android/iOS/Harmony)的 User-Agent 均以 "SiYuan/" 开头,
+// 其余视为浏览器。该口径与前端 getFrontend()、electron/main.js 设置的 UA 前缀、
+// 以及 session 鉴权中既有的 HasPrefix(ua, "SiYuan/") 判断保持一致。
+func IsBrowserRequest(c *gin.Context) bool {
+ return !strings.HasPrefix(c.GetHeader("User-Agent"), "SiYuan/")
+}