From be6314bd53403811f581bd70b7f438b613cf10bb Mon Sep 17 00:00:00 2001 From: WJQSERVER Date: Tue, 31 Dec 2024 09:21:25 +0800 Subject: [PATCH 001/303] 1.7.9 --- CHANGELOG.md | 7 +++++++ VERSION | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 503fb90..5e69110 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # 更新日志 +v1.7.9 +--- +- RELEASE: 安全性及小型修复, 建议用户自行选择是否升级 +- CHANGE: 将`logger`库作为外部库引入, 使维护性更好, 同时修正了部分日志问题并提升部分性能 +- CHANGE: 更新相关依赖库, 更新`req`库以解决`net`标准库的`CVE-2021-38561`漏洞 +- FIX: 修复安装脚本内的错误 + 24w28b --- - PRE-RELEASE: 此版本是v1.7.9的预发布版本,请勿在生产环境中使用 diff --git a/VERSION b/VERSION index 25a6ced..cb1ad9b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.7.8 \ No newline at end of file +1.7.9 \ No newline at end of file From 546a8ca98145bc095282488abed5ac6e8ad6b578 Mon Sep 17 00:00:00 2001 From: WJQSERVER Date: Tue, 31 Dec 2024 19:41:00 +0800 Subject: [PATCH 002/303] 24w29a --- CHANGELOG.md | 6 ++++++ DEV-VERSION | 2 +- config/config.go | 7 ++++--- config/config.toml | 1 + deploy/config.toml | 1 + docker/dockerfile/nocache/config.toml | 1 + go.mod | 4 ++-- go.sum | 18 ++++++++++-------- main.go | 5 ----- proxy/proxy.go | 11 +++++++++++ 10 files changed, 37 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e69110..64bd770 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # 更新日志 +24w29a +--- +- PRE-RELEASE: 此版本是一个实验性功能测试版本,请勿在生产环境中使用; 同时,这也是2024年的最后一个pre-release版本 +- ADD: `Auth` token参数透传至`"Authorization: token {token}"`, 为私有仓库拉取提供一定便利性(需要更多测试) +- CHANGE: 更新相关依赖库 + v1.7.9 --- - RELEASE: 安全性及小型修复, 建议用户自行选择是否升级 diff --git a/DEV-VERSION b/DEV-VERSION index 0a3d11b..49b6723 100644 --- a/DEV-VERSION +++ b/DEV-VERSION @@ -1 +1 @@ -24w28b +24w29a diff --git a/config/config.go b/config/config.go index bf9e30f..1b9a028 100644 --- a/config/config.go +++ b/config/config.go @@ -37,9 +37,10 @@ type CORSConfig struct { } type AuthConfig struct { - Enabled bool `toml:"enabled"` - AuthMethod string `toml:"authMethod"` - AuthToken string `toml:"authToken"` + Enabled bool `toml:"enabled"` + AuthMethod string `toml:"authMethod"` + AuthToken string `toml:"authToken"` + PassThrough bool `toml:"passThrough"` } type BlacklistConfig struct { diff --git a/config/config.toml b/config/config.toml index 2f6b177..e4cc2e7 100644 --- a/config/config.toml +++ b/config/config.toml @@ -19,6 +19,7 @@ enabled = true authMethod = "parameters" # "header" or "parameters" authToken = "token" enabled = false +passThrough = false [blacklist] blacklistFile = "/data/ghproxy/config/blacklist.json" diff --git a/deploy/config.toml b/deploy/config.toml index c451cc4..f3f9e16 100644 --- a/deploy/config.toml +++ b/deploy/config.toml @@ -19,6 +19,7 @@ enabled = true authMethod = "parameters" # "header" or "parameters" authToken = "token" enabled = false +passThrough = false [blacklist] blacklistFile = "/usr/local/ghproxy/config/blacklist.json" diff --git a/docker/dockerfile/nocache/config.toml b/docker/dockerfile/nocache/config.toml index dc2d8f5..aca6281 100644 --- a/docker/dockerfile/nocache/config.toml +++ b/docker/dockerfile/nocache/config.toml @@ -19,6 +19,7 @@ enabled = true authMethod = "parameters" # "header" or "parameters" authToken = "token" enabled = false +passThrough = false [blacklist] blacklistFile = "/data/ghproxy/config/blacklist.json" diff --git a/go.mod b/go.mod index 97b7766..b306cae 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( github.com/cloudwego/base64x v0.1.4 // indirect github.com/cloudwego/iasm v0.2.0 // indirect github.com/gabriel-vasile/mimetype v1.4.7 // indirect - github.com/gin-contrib/sse v0.1.0 // indirect + github.com/gin-contrib/sse v1.0.0 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.23.0 // indirect @@ -34,7 +34,7 @@ require ( github.com/mattn/go-isatty v0.0.20 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/onsi/ginkgo/v2 v2.22.1 // indirect + github.com/onsi/ginkgo/v2 v2.22.2 // indirect github.com/pelletier/go-toml/v2 v2.2.3 // indirect github.com/quic-go/qpack v0.5.1 // indirect github.com/quic-go/quic-go v0.48.2 // indirect diff --git a/go.sum b/go.sum index cc84f74..e86fec6 100644 --- a/go.sum +++ b/go.sum @@ -20,8 +20,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/gabriel-vasile/mimetype v1.4.7 h1:SKFKl7kD0RiPdbht0s7hFtjl489WcQ1VyPW8ZzUMYCA= github.com/gabriel-vasile/mimetype v1.4.7/go.mod h1:GDlAgAyIRT27BhFl53XNAFtfjzOkLaF35JdEG0P7LtU= -github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= -github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= +github.com/gin-contrib/sse v1.0.0 h1:y3bT1mUWUxDpW4JLQg/HnTqV4rozuW4tC9eFKTxYI9E= +github.com/gin-contrib/sse v1.0.0/go.mod h1:zNuFdwarAygJBht0NTKiSi3jRf6RbqeILZ9Sp6Slhe0= github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU= github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= @@ -67,10 +67,10 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= -github.com/onsi/ginkgo/v2 v2.22.1 h1:QW7tbJAUDyVDVOM5dFa7qaybo+CRfR7bemlQUN6Z8aM= -github.com/onsi/ginkgo/v2 v2.22.1/go.mod h1:S6aTpoRsSq2cZOd+pssHAlKW/Q/jZt6cPrPlnj4a1xM= -github.com/onsi/gomega v1.36.1 h1:bJDPBO7ibjxcbHMgSCoo4Yj18UWbKDlLwX1x9sybDcw= -github.com/onsi/gomega v1.36.1/go.mod h1:PvZbdDc8J6XJEpDK4HCuRBm8a6Fzp9/DmhC9C7yFlog= +github.com/onsi/ginkgo/v2 v2.22.2 h1:/3X8Panh8/WwhU/3Ssa6rCKqPLuAkVY2I0RoyDLySlU= +github.com/onsi/ginkgo/v2 v2.22.2/go.mod h1:oeMosUL+8LtarXBHu/c0bx2D/K9zyQ6uX3cTyztHwsk= +github.com/onsi/gomega v1.36.2 h1:koNYke6TVk6ZmnyHrCXba/T/MoLBXFjeC1PtvYgw0A8= +github.com/onsi/gomega v1.36.2/go.mod h1:DdwyADRjrc825LhMEkD76cHR5+pUnjhUN8GlHlRPHzY= github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M= github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -84,13 +84,15 @@ github.com/refraction-networking/utls v1.6.7/go.mod h1:BC3O4vQzye5hqpmDTWUqi4P5D github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= +github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= diff --git a/main.go b/main.go index 85fa202..3734e14 100644 --- a/main.go +++ b/main.go @@ -100,11 +100,6 @@ func init() { } else { router.UseH2C = false } - /*if !cfg.Server.EnableH2C { - router.UseH2C = false - } else { - router.UseH2C = true - }*/ setupApi(cfg, router, version) diff --git a/proxy/proxy.go b/proxy/proxy.go index adbb8cc..1faf52b 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -197,6 +197,7 @@ func ProxyRequest(c *gin.Context, u string, cfg *config.Config, mode string) { req := client.R().SetBody(body) setRequestHeaders(c, req) + authPassThrough(c, cfg) resp, err := SendRequest(c, req, method, u) if err != nil { @@ -250,6 +251,16 @@ func setRequestHeaders(c *gin.Context, req *req.Request) { } } +func authPassThrough(c *gin.Context, cfg *config.Config) { + // 判断 + if cfg.Auth.AuthMethod == "parameters" && !cfg.Auth.Enabled { + // 获取参数(token) + token := c.Query("token") + // 写入Header + c.Header("Authorization", "token "+token) + } +} + // 复制响应体 func copyResponseBody(c *gin.Context, respBody io.Reader) error { _, err := io.Copy(c.Writer, respBody) From 8371f9564f22f346208e6f787cfd95c5ec9a1dee Mon Sep 17 00:00:00 2001 From: WJQSERVER Date: Wed, 1 Jan 2025 08:44:27 +0800 Subject: [PATCH 003/303] add .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eee416a --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +demo.toml \ No newline at end of file From 83e6b78a93158156174599f12e0cbeb18f6f6805 Mon Sep 17 00:00:00 2001 From: WJQSERVER Date: Wed, 1 Jan 2025 08:45:21 +0800 Subject: [PATCH 004/303] add embed.FS and debug --- .github/workflows/build-dev.yml | 2 +- config/config.go | 1 + config/config.toml | 1 + deploy/config.toml | 1 + docker/dockerfile/nocache/config.toml | 1 + main.go | 32 ++++++++++++++++++++++----- 6 files changed, 31 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build-dev.yml b/.github/workflows/build-dev.yml index 715f49b..4a3a226 100644 --- a/.github/workflows/build-dev.yml +++ b/.github/workflows/build-dev.yml @@ -37,7 +37,7 @@ jobs: GOOS: ${{ matrix.goos }} GOARCH: ${{ matrix.goarch }} run: | - CGO_ENABLED=0 go build -ldflags "-X main.version=${{ env.VERSION }}" -o ${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}} ./main.go + CGO_ENABLED=0 go build -ldflags "-X main.version=${{ env.VERSION }} -X main.dev=true" -o ${{ env.OUTPUT_BINARY }}-${{matrix.goos}}-${{matrix.goarch}} ./main.go - name: 打包 run: | mkdir ghproxyd diff --git a/config/config.go b/config/config.go index 1b9a028..ea325a4 100644 --- a/config/config.go +++ b/config/config.go @@ -20,6 +20,7 @@ type ServerConfig struct { Host string `toml:"host"` SizeLimit int `toml:"sizeLimit"` EnableH2C string `toml:"enableH2C"` + Debug bool `toml:"debug"` } type PagesConfig struct { diff --git a/config/config.toml b/config/config.toml index e4cc2e7..5aff583 100644 --- a/config/config.toml +++ b/config/config.toml @@ -3,6 +3,7 @@ host = "127.0.0.1" port = 8080 sizeLimit = 125 # MB enableH2C = "on" # "on" or "off" +debug = false [pages] enabled = false diff --git a/deploy/config.toml b/deploy/config.toml index f3f9e16..4afc4c2 100644 --- a/deploy/config.toml +++ b/deploy/config.toml @@ -3,6 +3,7 @@ host = "127.0.0.1" port = 8080 sizeLimit = 125 # MB enableH2C = false +debug = false [pages] enabled = true diff --git a/docker/dockerfile/nocache/config.toml b/docker/dockerfile/nocache/config.toml index aca6281..a0a4815 100644 --- a/docker/dockerfile/nocache/config.toml +++ b/docker/dockerfile/nocache/config.toml @@ -3,6 +3,7 @@ host = "0.0.0.0" port = 80 #修改此配置会导致容器异常 sizeLimit = 125 # MB enableH2C = "off" # on / off +debug = false [pages] enabled = true diff --git a/main.go b/main.go index 3734e14..9814cad 100644 --- a/main.go +++ b/main.go @@ -1,8 +1,10 @@ package main import ( + "embed" "flag" "fmt" + "io/fs" "log" "net/http" "time" @@ -24,10 +26,17 @@ var ( configfile = "/data/ghproxy/config/config.toml" cfgfile string version string + dev bool + runMode string limiter *rate.RateLimiter iplimiter *rate.IPRateLimiter ) +var ( + //go:embed pages/* + pagesFS embed.FS +) + var ( logw = logger.Logw logInfo = logger.LogInfo @@ -89,7 +98,16 @@ func init() { loadlist(cfg) setupRateLimit(cfg) - gin.SetMode(gin.ReleaseMode) + if cfg.Server.Debug { + dev = true + } + if dev { + gin.SetMode(gin.DebugMode) + runMode = "dev" + } else { + gin.SetMode(gin.ReleaseMode) + runMode = "release" + } router = gin.Default() //H2C默认值为true,而后遵循cfg.Server.EnableH2C的设置 @@ -112,14 +130,16 @@ func init() { }) router.StaticFile("/favicon.ico", faviconPath) } else if !cfg.Pages.Enabled { - router.GET("/", func(c *gin.Context) { - c.String(http.StatusForbidden, "403 Forbidden Access") - logWarning("403 > Path:/ IP:%s UA:%s METHOD:%s HTTPv:%s", c.ClientIP(), c.Request.UserAgent(), c.Request.Method, c.Request.Proto) - }) + pages, err := fs.Sub(pagesFS, "pages") + if err != nil { + log.Fatalf("Failed when processing pages: %s", err) + } + router.GET("/", gin.WrapH(http.FileServer(http.FS(pages)))) + router.GET("/favicon.ico", gin.WrapH(http.FileServer(http.FS(pages)))) } router.NoRoute(func(c *gin.Context) { - proxy.NoRouteHandler(cfg, limiter, iplimiter)(c) + proxy.NoRouteHandler(cfg, limiter, iplimiter, runMode)(c) }) } From acd38f4fe0f13c8f16071b831b5fec53b3d993e4 Mon Sep 17 00:00:00 2001 From: WJQSERVER Date: Wed, 1 Jan 2025 08:45:29 +0800 Subject: [PATCH 005/303] update authPassThrough --- proxy/proxy.go | 58 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 11 deletions(-) diff --git a/proxy/proxy.go b/proxy/proxy.go index 1faf52b..1238358 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -34,7 +34,7 @@ var exps = []*regexp.Regexp{ regexp.MustCompile(`^(?:https?://)?api\.github\.com/repos/([^/]+)/([^/]+)/.*`), } -func NoRouteHandler(cfg *config.Config, limiter *rate.RateLimiter, iplimiter *rate.IPRateLimiter) gin.HandlerFunc { +func NoRouteHandler(cfg *config.Config, limiter *rate.RateLimiter, iplimiter *rate.IPRateLimiter, runMode string) gin.HandlerFunc { return func(c *gin.Context) { // 限制访问频率 if cfg.RateLimit.Enabled { @@ -134,9 +134,9 @@ func NoRouteHandler(cfg *config.Config, limiter *rate.RateLimiter, iplimiter *ra switch { case exps[0].MatchString(rawPath), exps[1].MatchString(rawPath), exps[3].MatchString(rawPath), exps[4].MatchString(rawPath): - ProxyRequest(c, rawPath, cfg, "chrome") + ProxyRequest(c, rawPath, cfg, "chrome", runMode) case exps[2].MatchString(rawPath): - ProxyRequest(c, rawPath, cfg, "git") + ProxyRequest(c, rawPath, cfg, "git", runMode) default: c.String(http.StatusForbidden, "Invalid input.") fmt.Println("Invalid input.") @@ -167,11 +167,14 @@ func MatchUserRepo(rawPath string, cfg *config.Config, c *gin.Context, matches [ return "", "" } -func ProxyRequest(c *gin.Context, u string, cfg *config.Config, mode string) { +func ProxyRequest(c *gin.Context, u string, cfg *config.Config, mode string, runMode string) { method := c.Request.Method logInfo("%s %s %s %s %s", c.ClientIP(), method, u, c.Request.Header.Get("User-Agent"), c.Request.Proto) client := createHTTPClient(mode) + if runMode == "dev" { + client.DevMode() + } // 发送HEAD请求, 预获取Content-Length headReq := client.R() @@ -197,7 +200,7 @@ func ProxyRequest(c *gin.Context, u string, cfg *config.Config, mode string) { req := client.R().SetBody(body) setRequestHeaders(c, req) - authPassThrough(c, cfg) + authPassThrough(c, cfg, req) resp, err := SendRequest(c, req, method, u) if err != nil { @@ -251,13 +254,46 @@ func setRequestHeaders(c *gin.Context, req *req.Request) { } } -func authPassThrough(c *gin.Context, cfg *config.Config) { - // 判断 - if cfg.Auth.AuthMethod == "parameters" && !cfg.Auth.Enabled { - // 获取参数(token) +/* + func authPassThrough(c *gin.Context, cfg *config.Config, req *req.Request) { + if cfg.Auth.PassThrough && cfg.Auth.AuthMethod == "parameters" && !cfg.Auth.Enabled { + // only mode + token := c.Query("token") + req.SetHeader("Authorization", "token "+token) + } else if cfg.Auth.PassThrough && cfg.Auth.AuthMethod == "header" && cfg.Auth.Enabled { + // mix mode + token := c.Query("token") + req.SetHeader("Authorization", "token "+token) + } else if cfg.Auth.PassThrough && cfg.Auth.AuthMethod == "parameters" && cfg.Auth.Enabled { + // conflict + 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) + c.JSON(http.StatusForbidden, gin.H{"error": "Conflict Auth Method"}) + return + } else if cfg.Auth.PassThrough && cfg.Auth.AuthMethod == "header" && !cfg.Auth.Enabled { + // only mode + token := c.Query("token") + req.SetHeader("Authorization", "token "+token) + } + } +*/ + +func authPassThrough(c *gin.Context, cfg *config.Config, req *req.Request) { + if cfg.Auth.PassThrough { token := c.Query("token") - // 写入Header - c.Header("Authorization", "token "+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) + } + 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) + } } } From 90b9c69dadaeb233e28d359dab879338981b94b3 Mon Sep 17 00:00:00 2001 From: WJQSERVER Date: Wed, 1 Jan 2025 08:45:53 +0800 Subject: [PATCH 006/303] 25w01a --- CHANGELOG.md | 8 ++++++++ DEV-VERSION | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64bd770..82d3b96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # 更新日志 +25w01a +--- +- PRE-RELEASE: 此版本是v1.8.0的预发布版本,请勿在生产环境中使用; 同时,这也是2025年的第一个pre-release版本,祝各位新年快乐! (同时,请注意版本号的变化) +- ADD: 加入`dev`参数, 以便pre-release版本调试(实验性) +- ADD: 加入基于`embed.FS`的内嵌前端, config.toml中的`[pages]`配置为false时自动使用内嵌前端 +- CHANGE: 完善24w29a版本新加入的`Auth`参数透传至`"Authorization: token {token}"`功能,对相关逻辑进行完善 +- FIX: 修正24w29a版本新加入的`Auth`参数透传至`"Authorization: token {token}"`功能的一些问题 + 24w29a --- - PRE-RELEASE: 此版本是一个实验性功能测试版本,请勿在生产环境中使用; 同时,这也是2024年的最后一个pre-release版本 diff --git a/DEV-VERSION b/DEV-VERSION index 49b6723..d5f6ac9 100644 --- a/DEV-VERSION +++ b/DEV-VERSION @@ -1 +1 @@ -24w29a +25w01a \ No newline at end of file From de65889a4d3b9731a1cfd5e32b01a5cd30862aa2 Mon Sep 17 00:00:00 2001 From: WJQSERVER Date: Wed, 1 Jan 2025 08:50:28 +0800 Subject: [PATCH 007/303] fix --- main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 9814cad..a0d5546 100644 --- a/main.go +++ b/main.go @@ -26,7 +26,7 @@ var ( configfile = "/data/ghproxy/config/config.toml" cfgfile string version string - dev bool + dev string runMode string limiter *rate.RateLimiter iplimiter *rate.IPRateLimiter @@ -99,9 +99,9 @@ func init() { setupRateLimit(cfg) if cfg.Server.Debug { - dev = true + dev = "true" } - if dev { + if dev == "true" { gin.SetMode(gin.DebugMode) runMode = "dev" } else { From e4252d0596e0c5372dac92caddde050b32b3bfc8 Mon Sep 17 00:00:00 2001 From: WJQSERVER Date: Thu, 2 Jan 2025 10:37:18 +0800 Subject: [PATCH 008/303] update caddy --- CHANGELOG.md | 5 +++++ DEV-VERSION | 2 +- docker/dockerfile/dev/Dockerfile | 4 ++-- docker/dockerfile/release/Dockerfile | 4 ++-- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 82d3b96..1825be6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # 更新日志 +25w01b +--- +- PRE-RELEASE: 此版本是v1.8.0的预发布版本,请勿在生产环境中使用 +- CHANGE: 将底包更新至`v2.9.0` + 25w01a --- - PRE-RELEASE: 此版本是v1.8.0的预发布版本,请勿在生产环境中使用; 同时,这也是2025年的第一个pre-release版本,祝各位新年快乐! (同时,请注意版本号的变化) diff --git a/DEV-VERSION b/DEV-VERSION index d5f6ac9..2f8a75c 100644 --- a/DEV-VERSION +++ b/DEV-VERSION @@ -1 +1 @@ -25w01a \ No newline at end of file +25w01b \ No newline at end of file diff --git a/docker/dockerfile/dev/Dockerfile b/docker/dockerfile/dev/Dockerfile index 465ac6b..5fa5637 100644 --- a/docker/dockerfile/dev/Dockerfile +++ b/docker/dockerfile/dev/Dockerfile @@ -1,4 +1,4 @@ -FROM wjqserver/caddy:v24.12.20-alpine AS builder +FROM wjqserver/caddy:2.9.0-alpine AS builder ARG USER=WJQSERVER-STUDIO ARG REPO=ghproxy @@ -36,7 +36,7 @@ RUN wget -O /data/${APPLICATION}/whitelist.json https://raw.githubusercontent.co RUN chmod +x /data/${APPLICATION}/${APPLICATION} RUN chmod +x /usr/local/bin/init.sh -FROM wjqserver/caddy:v24.12.20-alpine +FROM wjqserver/caddy:2.9.0-alpine RUN apk add --no-cache curl diff --git a/docker/dockerfile/release/Dockerfile b/docker/dockerfile/release/Dockerfile index eb750df..3b2302e 100644 --- a/docker/dockerfile/release/Dockerfile +++ b/docker/dockerfile/release/Dockerfile @@ -1,4 +1,4 @@ -FROM wjqserver/caddy:v24.12.20-alpine AS builder +FROM wjqserver/caddy:2.9.0-alpine AS builder ARG USER=WJQSERVER-STUDIO ARG REPO=ghproxy @@ -36,7 +36,7 @@ RUN wget -O /data/${APPLICATION}/whitelist.json https://raw.githubusercontent.co RUN chmod +x /data/${APPLICATION}/${APPLICATION} RUN chmod +x /usr/local/bin/init.sh -FROM wjqserver/caddy:v24.12.20-alpine +FROM wjqserver/caddy:2.9.0-alpine RUN apk add --no-cache curl From a281d4c779cc7615d7a5ad4a7261d6c5e11ae9a7 Mon Sep 17 00:00:00 2001 From: WJQSERVER Date: Fri, 3 Jan 2025 17:25:15 +0800 Subject: [PATCH 009/303] 25w01c --- CHANGELOG.md | 5 +++++ DEV-VERSION | 2 +- proxy/proxy.go | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1825be6..2f947c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # 更新日志 +25w01c +--- +- PRE-RELEASE: 此版本是v1.8.0的预发布版本,请勿在生产环境中使用 +- CHANGE: 改进token参数透传功能 + 25w01b --- - PRE-RELEASE: 此版本是v1.8.0的预发布版本,请勿在生产环境中使用 diff --git a/DEV-VERSION b/DEV-VERSION index 2f8a75c..3fb0839 100644 --- a/DEV-VERSION +++ b/DEV-VERSION @@ -1 +1 @@ -25w01b \ No newline at end of file +25w01c \ No newline at end of file diff --git a/proxy/proxy.go b/proxy/proxy.go index 1238358..1704dc2 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -286,6 +286,9 @@ func authPassThrough(c *gin.Context, cfg *config.Config, req *req.Request) { 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 { @@ -293,6 +296,9 @@ func authPassThrough(c *gin.Context, cfg *config.Config, req *req.Request) { } 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 } } } From 972baee564a7422532fbab0ef348c2326a89daca Mon Sep 17 00:00:00 2001 From: WJQSERVER Date: Fri, 3 Jan 2025 18:45:25 +0800 Subject: [PATCH 010/303] 25w01d --- .gitignore | 4 +++- CHANGELOG.md | 5 +++++ DEV-VERSION | 2 +- proxy/proxy.go | 1 + 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index eee416a..3431fbc 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -demo.toml \ No newline at end of file +demo.toml +dev +*.log \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f947c1..8e023cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # 更新日志 +25w01d +--- +- PRE-RELEASE: 此版本是v1.8.0的预发布版本,请勿在生产环境中使用 +- CHANGE: 尝试修复部分问题 + 25w01c --- - PRE-RELEASE: 此版本是v1.8.0的预发布版本,请勿在生产环境中使用 diff --git a/DEV-VERSION b/DEV-VERSION index 3fb0839..6cb0584 100644 --- a/DEV-VERSION +++ b/DEV-VERSION @@ -1 +1 @@ -25w01c \ No newline at end of file +25w01d \ No newline at end of file diff --git a/proxy/proxy.go b/proxy/proxy.go index 1704dc2..eeca0fa 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -179,6 +179,7 @@ func ProxyRequest(c *gin.Context, u string, cfg *config.Config, mode string, run // 发送HEAD请求, 预获取Content-Length headReq := client.R() setRequestHeaders(c, headReq) + authPassThrough(c, cfg, headReq) headResp, err := headReq.Head(u) if err != nil { From a0e5846e113cc4dd09f689f365dbf4e71d6e2cdc Mon Sep 17 00:00:00 2001 From: WJQSERVER Date: Fri, 3 Jan 2025 21:20:10 +0800 Subject: [PATCH 011/303] 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 } } } From 17a2ba173d942f3ad47c94e234af7dce1a337bb5 Mon Sep 17 00:00:00 2001 From: WJQSERVER Date: Sun, 5 Jan 2025 11:57:47 +0800 Subject: [PATCH 012/303] update deps --- go.mod | 10 +++++----- go.sum | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index b306cae..5a5e0e3 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/WJQSERVER-STUDIO/go-utils/logger v1.1.0 github.com/gin-gonic/gin v1.10.0 github.com/imroc/req/v3 v3.49.1 - golang.org/x/time v0.8.0 + golang.org/x/time v0.9.0 ) require ( @@ -17,7 +17,7 @@ require ( github.com/cloudflare/circl v1.5.0 // indirect github.com/cloudwego/base64x v0.1.4 // indirect github.com/cloudwego/iasm v0.2.0 // indirect - github.com/gabriel-vasile/mimetype v1.4.7 // indirect + github.com/gabriel-vasile/mimetype v1.4.8 // indirect github.com/gin-contrib/sse v1.0.0 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect @@ -42,13 +42,13 @@ require ( github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.12 // indirect go.uber.org/mock v0.5.0 // indirect - golang.org/x/arch v0.12.0 // indirect + golang.org/x/arch v0.13.0 // indirect golang.org/x/crypto v0.31.0 // indirect - golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 // indirect + golang.org/x/exp v0.0.0-20250103183323-7d7fa50e5329 // indirect golang.org/x/mod v0.22.0 // indirect golang.org/x/net v0.33.0 // indirect golang.org/x/sync v0.10.0 // indirect - golang.org/x/sys v0.28.0 // indirect + golang.org/x/sys v0.29.0 // indirect golang.org/x/text v0.21.0 // indirect golang.org/x/tools v0.28.0 // indirect google.golang.org/protobuf v1.36.1 // indirect diff --git a/go.sum b/go.sum index e86fec6..29590c0 100644 --- a/go.sum +++ b/go.sum @@ -18,8 +18,8 @@ github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/gabriel-vasile/mimetype v1.4.7 h1:SKFKl7kD0RiPdbht0s7hFtjl489WcQ1VyPW8ZzUMYCA= -github.com/gabriel-vasile/mimetype v1.4.7/go.mod h1:GDlAgAyIRT27BhFl53XNAFtfjzOkLaF35JdEG0P7LtU= +github.com/gabriel-vasile/mimetype v1.4.8 h1:FfZ3gj38NjllZIeJAmMhr+qKL8Wu+nOoI3GqacKw1NM= +github.com/gabriel-vasile/mimetype v1.4.8/go.mod h1:ByKUIKGjh1ODkGM1asKUbQZOLGrPjydw3hYPU2YU9t8= github.com/gin-contrib/sse v1.0.0 h1:y3bT1mUWUxDpW4JLQg/HnTqV4rozuW4tC9eFKTxYI9E= github.com/gin-contrib/sse v1.0.0/go.mod h1:zNuFdwarAygJBht0NTKiSi3jRf6RbqeILZ9Sp6Slhe0= github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU= @@ -101,12 +101,12 @@ github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZ github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E= go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU= go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM= -golang.org/x/arch v0.12.0 h1:UsYJhbzPYGsT0HbEdmYcqtCv8UNGvnaL561NnIUvaKg= -golang.org/x/arch v0.12.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= +golang.org/x/arch v0.13.0 h1:KCkqVVV1kGg0X87TFysjCJ8MxtZEIU4Ja/yXGeoECdA= +golang.org/x/arch v0.13.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= -golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67 h1:1UoZQm6f0P/ZO0w1Ri+f+ifG/gXhegadRdwBIXEFWDo= -golang.org/x/exp v0.0.0-20241217172543-b2144cdd0a67/go.mod h1:qj5a5QZpwLU2NLQudwIN5koi3beDhSAlJwa67PuM98c= +golang.org/x/exp v0.0.0-20250103183323-7d7fa50e5329 h1:9kj3STMvgqy3YA4VQXBrN7925ICMxD5wzMRcgA30588= +golang.org/x/exp v0.0.0-20250103183323-7d7fa50e5329/go.mod h1:qj5a5QZpwLU2NLQudwIN5koi3beDhSAlJwa67PuM98c= golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4= golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I= @@ -114,12 +114,12 @@ golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= -golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU= +golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= -golang.org/x/time v0.8.0 h1:9i3RxcPv3PZnitoVGMPDKZSq1xW1gK1Xy3ArNOGZfEg= -golang.org/x/time v0.8.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= +golang.org/x/time v0.9.0 h1:EsRrnYcQiGH+5FfbgvV4AP7qEZstoyrHB0DzarOQ4ZY= +golang.org/x/time v0.9.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.28.0 h1:WuB6qZ4RPCQo5aP3WdKZS7i595EdWqWR8vqJTlwTVK8= golang.org/x/tools v0.28.0/go.mod h1:dcIOrVd3mfQKTgrDVQHqCPMWy6lnhfhtX3hLXYVLfRw= google.golang.org/protobuf v1.36.1 h1:yBPeRvTftaleIgM3PZ/WBIZ7XM/eEYAaEyCwvyjq/gk= From 2aa665d89a0137bb9e2bd47dffd3f81ff3f8ef9a Mon Sep 17 00:00:00 2001 From: WJQSERVER Date: Sun, 5 Jan 2025 11:58:28 +0800 Subject: [PATCH 013/303] update copyright info --- pages/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/index.html b/pages/index.html index c37afa5..b3de9fd 100644 --- a/pages/index.html +++ b/pages/index.html @@ -463,7 +463,7 @@