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: Authentication middleware compatible (#9720)
Yingyi / 颖逸f38c52292b44
diff --git a/kernel/model/session.go b/kernel/model/session.goindex 4243887f59..e8921d4134 100644--- a/kernel/model/session.go+++ b/kernel/model/session.go@@ -162,6 +162,12 @@ func CheckAuth(c *gin.Context) {// 未设置访问授权码if "" == Conf.AccessAuthCode {+ // Skip the empty access authorization code check https://github.com/siyuan-note/siyuan/issues/9709+ if util.SIYUAN_ACCESS_AUTH_CODE_BYPASS {+ c.Next()+ return+ }+// Authenticate requests with the Origin header other than 127.0.0.1 https://github.com/siyuan-note/siyuan/issues/9180clientIP := c.ClientIP()host := c.GetHeader("Host")diff --git a/kernel/util/working.go b/kernel/util/working.goindex 6bcceb5670..78ec781a69 100644--- a/kernel/util/working.go+++ b/kernel/util/working.go@@ -46,6 +46,21 @@ const (IsInsider = false)+var (+ RUN_IN_CONTAINER = false // 是否运行在容器中+ SIYUAN_ACCESS_AUTH_CODE_BYPASS = false // 是否跳过空访问授权码检查+)++func initEnvVars() {+ var err error++ RUN_IN_CONTAINER = isRunningInDockerContainer()++ if SIYUAN_ACCESS_AUTH_CODE_BYPASS, err = strconv.ParseBool(os.Getenv("SIYUAN_ACCESS_AUTH_CODE_BYPASS")); nil != err {+ SIYUAN_ACCESS_AUTH_CODE_BYPASS = false+ }+}+var (bootProgress float64 // 启动进度,从 0 到 100bootDetails string // 启动细节描述@@ -53,6 +68,7 @@ var ()func Boot() {+ initEnvVars()IncBootProgress(3, "Booting kernel...")rand.Seed(time.Now().UTC().UnixNano())initMime()@@ -79,15 +95,13 @@ func Boot() {ReadOnly, _ = strconv.ParseBool(*readOnly)AccessAuthCode = *accessAuthCodeContainer = ContainerStd- if isRunningInDockerContainer() {+ if RUN_IN_CONTAINER {Container = ContainerDockerif "" == AccessAuthCode {interruptBoot := true- // Set the env `SIYUAN_ACCESS_AUTH_CODE_BYPASS=true` to skip checking access auth code when deploying Docker https://github.com/siyuan-note/siyuan/issues/9709- byPassEnv := os.Getenv("SIYUAN_ACCESS_AUTH_CODE_BYPASS")- bypass, parseErr := strconv.ParseBool(byPassEnv)- if nil == parseErr && bypass {+ // Set the env `SIYUAN_ACCESS_AUTH_CODE_BYPASS=true` to skip checking empty access auth code https://github.com/siyuan-note/siyuan/issues/9709+ if SIYUAN_ACCESS_AUTH_CODE_BYPASS {interruptBoot = falsefmt.Println("bypass access auth code check since the env [SIYUAN_ACCESS_AUTH_CODE_BYPASS] is set to [true]")}