diff --git a/kernel/model/session.go b/kernel/model/session.go index 4243887f5..e8921d413 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/9180 clientIP := c.ClientIP() host := c.GetHeader("Host") diff --git a/kernel/util/working.go b/kernel/util/working.go index 6bcceb567..78ec781a6 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 到 100 bootDetails 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 = *accessAuthCode Container = ContainerStd - if isRunningInDockerContainer() { + if RUN_IN_CONTAINER { Container = ContainerDocker if "" == 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 = false fmt.Println("bypass access auth code check since the env [SIYUAN_ACCESS_AUTH_CODE_BYPASS] is set to [true]") }