Skip to content

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

:lock: Require explicit --enable-pprof and admin auth for debug endpoints https://github.com/siyuan-note/siyuan/security/advisories/GHSA-9cqq-p2hw-mj3f

Daniel90f74c8d7827
diff --git a/kernel/cli/cmd/serve.go b/kernel/cli/cmd/serve.go
index f173a4751a..eefa42acc8 100644
--- a/kernel/cli/cmd/serve.go
+++ b/kernel/cli/cmd/serve.go
@@ -40,6 +40,7 @@ var (
serveSSL bool
serveAttachUI bool
serveSafeMode bool
+ serveEnablePprof bool
)
var serveCmd = &cobra.Command{
@@ -60,7 +61,7 @@ var serveCmd = &cobra.Command{
// --workspace 优先取 serve 自己的(rootCmd 的 persistent flag),兜底环境变量与默认值交给 util.BootWithFlags 内部处理(与原 Boot() 行为一致)。
ws := workspacePath
- util.BootWithFlags(ws, serveWdPath, servePort, serveReadOnly, serveAccessAuthCode, serveLang, serveMode, serveSSL, serveAttachUI, serveSafeMode)
+ util.BootWithFlags(ws, serveWdPath, servePort, serveReadOnly, serveAccessAuthCode, serveLang, serveMode, serveSSL, serveAttachUI, serveSafeMode, serveEnablePprof)
model.InitJwtKey()
model.InitConf()
@@ -103,10 +104,11 @@ func init() {
serveCmd.Flags().StringVar(&serveReadOnly, "readonly", "false", "read-only mode")
serveCmd.Flags().StringVar(&serveAccessAuthCode, "accessAuthCode", "", "access auth code")
serveCmd.Flags().StringVar(&serveLang, "lang", "", "ar/de/en/es/fr/he/hi/id/it/ja/ko/nl/pl/pt-BR/ru/sk/th/tr/uk/zh-CN/zh-TW")
- serveCmd.Flags().StringVar(&serveMode, "mode", "prod", "dev/prod")
+ serveCmd.Flags().StringVar(&serveMode, "mode", "prod", "dev/prod (non-prod values must not be used on network-exposed instances)")
serveCmd.Flags().BoolVar(&serveSSL, "ssl", false, "for https and wss")
serveCmd.Flags().BoolVar(&serveAttachUI, "attach-ui", false, "attach kernel lifecycle to desktop UI process (used by Electron)")
serveCmd.Flags().BoolVar(&serveSafeMode, "safe-mode", false, "boot in safe mode")
+ serveCmd.Flags().BoolVar(&serveEnablePprof, "enable-pprof", false, "register unauthenticated /debug/pprof/ endpoints exposing process memory dumps (dev only, never enable on a network-exposed instance)")
rootCmd.AddCommand(serveCmd)
}
diff --git a/kernel/server/serve.go b/kernel/server/serve.go
index ed9bb5db69..03cf3945a9 100644
--- a/kernel/server/serve.go
+++ b/kernel/server/serve.go
@@ -1231,22 +1231,22 @@ func serveRepoDiff(ginServer *gin.Engine) {
}
func serveDebug(ginServer *gin.Engine) {
- if "prod" == util.Mode {
- // The production environment will no longer register `/debug/pprof/` https://github.com/siyuan-note/siyuan/issues/10152
+ // 调试端点默认不注册,仅 --enable-pprof 显式开启;即使开启也要求管理员鉴权 https://github.com/siyuan-note/siyuan/security/advisories/GHSA-9cqq-p2hw-mj3f
+ if !util.EnablePprof {
return
}
- ginServer.GET("/debug/pprof/", gin.WrapF(pprof.Index))
- ginServer.GET("/debug/pprof/allocs", gin.WrapF(pprof.Index))
- ginServer.GET("/debug/pprof/block", gin.WrapF(pprof.Index))
- ginServer.GET("/debug/pprof/goroutine", gin.WrapF(pprof.Index))
- ginServer.GET("/debug/pprof/heap", gin.WrapF(pprof.Index))
- ginServer.GET("/debug/pprof/mutex", gin.WrapF(pprof.Index))
- ginServer.GET("/debug/pprof/threadcreate", gin.WrapF(pprof.Index))
- ginServer.GET("/debug/pprof/cmdline", gin.WrapF(pprof.Cmdline))
- ginServer.GET("/debug/pprof/profile", gin.WrapF(pprof.Profile))
- ginServer.GET("/debug/pprof/symbol", gin.WrapF(pprof.Symbol))
- ginServer.GET("/debug/pprof/trace", gin.WrapF(pprof.Trace))
+ ginServer.GET("/debug/pprof/", model.CheckAuth, model.CheckAdminRole, gin.WrapF(pprof.Index))
+ ginServer.GET("/debug/pprof/allocs", model.CheckAuth, model.CheckAdminRole, gin.WrapF(pprof.Index))
+ ginServer.GET("/debug/pprof/block", model.CheckAuth, model.CheckAdminRole, gin.WrapF(pprof.Index))
+ ginServer.GET("/debug/pprof/goroutine", model.CheckAuth, model.CheckAdminRole, gin.WrapF(pprof.Index))
+ ginServer.GET("/debug/pprof/heap", model.CheckAuth, model.CheckAdminRole, gin.WrapF(pprof.Index))
+ ginServer.GET("/debug/pprof/mutex", model.CheckAuth, model.CheckAdminRole, gin.WrapF(pprof.Index))
+ ginServer.GET("/debug/pprof/threadcreate", model.CheckAuth, model.CheckAdminRole, gin.WrapF(pprof.Index))
+ ginServer.GET("/debug/pprof/cmdline", model.CheckAuth, model.CheckAdminRole, gin.WrapF(pprof.Cmdline))
+ ginServer.GET("/debug/pprof/profile", model.CheckAuth, model.CheckAdminRole, gin.WrapF(pprof.Profile))
+ ginServer.GET("/debug/pprof/symbol", model.CheckAuth, model.CheckAdminRole, gin.WrapF(pprof.Symbol))
+ ginServer.GET("/debug/pprof/trace", model.CheckAuth, model.CheckAdminRole, gin.WrapF(pprof.Trace))
}
func serveWebSocket(ginServer *gin.Engine) {
diff --git a/kernel/util/working.go b/kernel/util/working.go
index e4964f9c69..965aa2b933 100644
--- a/kernel/util/working.go
+++ b/kernel/util/working.go
@@ -56,6 +56,7 @@ var (
RunInContainer = false // 是否运行在容器中
SiYuanAccessAuthCodeBypass = false // 是否跳过空锁屏密码检查
AttachUI = false // 是否绑定桌面 UI 进程生命周期(Electron 拉起时为 true,手动 serve 为 false)
+ EnablePprof = false // 是否注册未鉴权的调试端点,仅调试时显式开启,切勿在对外开放的实例上使用
)
func initEnvVars() {
@@ -130,15 +131,17 @@ func Boot() {
attachUI := flag.Bool("attach-ui", false, "attach kernel lifecycle to desktop UI process (used by Electron)")
lang := flag.String("lang", "", "ar/de/en/es/fr/he/hi/id/it/ja/ko/nl/pl/pt-BR/ru/sk/th/tr/uk/zh-CN/zh-TW")
mode := flag.String("mode", "prod", "dev/prod")
+ enablePprof := flag.Bool("enable-pprof", false, "enable unauthenticated /debug/pprof/ endpoints (dev only, never on a network-exposed instance)")
safeMode := flag.Bool("safe-mode", false, "boot in safe mode")
flag.Parse()
- BootWithFlags(*workspacePath, *wdPath, *port, *readOnly, *accessAuthCode, *lang, *mode, *ssl, *attachUI, *safeMode)
+ BootWithFlags(*workspacePath, *wdPath, *port, *readOnly, *accessAuthCode, *lang, *mode, *ssl, *attachUI, *safeMode, *enablePprof)
}
// BootWithFlags 接收已解析好的启动参数,完成环境变量回退、全局变量赋值、工作空间初始化与加锁等启动收尾工作。Boot()(标准库 flag 解析)和 serve 子命令(cobra 解析)都走这个统一入口。
-func BootWithFlags(workspacePath, wdPath, port, readOnly, accessAuthCode, lang, mode string, ssl, attachUI, safeMode bool) {
+func BootWithFlags(workspacePath, wdPath, port, readOnly, accessAuthCode, lang, mode string, ssl, attachUI, safeMode, enablePprof bool) {
SafeMode = safeMode
+ EnablePprof = enablePprof
// Fallback to env vars if commandline args are not set
// valid only for CLI args that default to "", as the
// others have explicit (sane) defaults