From a0e5846e113cc4dd09f689f365dbf4e71d6e2cdc Mon Sep 17 00:00:00 2001 From: WJQSERVER Date: Fri, 3 Jan 2025 21:20:10 +0800 Subject: [PATCH] 25w01e --- CHANGELOG.md | 5 +++++ DEV-VERSION | 2 +- proxy/proxy.go | 34 ++++++++++++++++++---------------- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e023cd..812378e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # 更新日志 +25w01e +--- +- PRE-RELEASE: 此版本是v1.8.0的预发布版本,请勿在生产环境中使用 +- FIX: 修复引入token参数透传功能导致的一些问题 + 25w01d --- - PRE-RELEASE: 此版本是v1.8.0的预发布版本,请勿在生产环境中使用 diff --git a/DEV-VERSION b/DEV-VERSION index 6cb0584..ac52583 100644 --- a/DEV-VERSION +++ b/DEV-VERSION @@ -1 +1 @@ -25w01d \ No newline at end of file +25w01e \ No newline at end of file diff --git a/proxy/proxy.go b/proxy/proxy.go index eeca0fa..8b1a230 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -281,25 +281,27 @@ func setRequestHeaders(c *gin.Context, req *req.Request) { func authPassThrough(c *gin.Context, cfg *config.Config, req *req.Request) { if cfg.Auth.PassThrough { token := c.Query("token") - switch cfg.Auth.AuthMethod { - case "parameters": - if !cfg.Auth.Enabled { - req.SetHeader("Authorization", "token "+token) - } else { - logWarning("%s %s %s %s %s Auth-Error: Conflict Auth Method", c.ClientIP(), c.Request.Method, c.Request.URL.String(), c.Request.Header.Get("User-Agent"), c.Request.Proto) + if token != "" { + switch cfg.Auth.AuthMethod { + case "parameters": + if !cfg.Auth.Enabled { + req.SetHeader("Authorization", "token "+token) + } else { + logWarning("%s %s %s %s %s Auth-Error: Conflict Auth Method", c.ClientIP(), c.Request.Method, c.Request.URL.String(), c.Request.Header.Get("User-Agent"), c.Request.Proto) + // 500 Internal Server Error + c.JSON(http.StatusInternalServerError, gin.H{"error": "Conflict Auth Method"}) + return + } + case "header": + if cfg.Auth.Enabled { + req.SetHeader("Authorization", "token "+token) + } + default: + logWarning("%s %s %s %s %s Invalid Auth Method / Auth Method is not be set", c.ClientIP(), c.Request.Method, c.Request.URL.String(), c.Request.Header.Get("User-Agent"), c.Request.Proto) // 500 Internal Server Error - c.JSON(http.StatusInternalServerError, gin.H{"error": "Conflict Auth Method"}) + c.JSON(http.StatusInternalServerError, gin.H{"error": "Invalid Auth Method / Auth Method is not be set"}) return } - case "header": - if cfg.Auth.Enabled { - req.SetHeader("Authorization", "token "+token) - } - default: - logWarning("%s %s %s %s %s Invalid Auth Method / Auth Method is not be set", c.ClientIP(), c.Request.Method, c.Request.URL.String(), c.Request.Header.Get("User-Agent"), c.Request.Proto) - // 500 Internal Server Error - c.JSON(http.StatusInternalServerError, gin.H{"error": "Invalid Auth Method / Auth Method is not be set"}) - return } } }