From 931f7a87377cb6f42b06091c2fbcfcc46766b2f8 Mon Sep 17 00:00:00 2001 From: Jacky Date: Wed, 8 May 2024 19:00:32 +0800 Subject: [PATCH] fix: proxy url query unescape issue #377 --- README-es.md | 2 +- README-vi_VN.md | 2 +- README-zh_CN.md | 2 +- README-zh_TW.md | 2 +- README.md | 2 +- router/proxy.go | 21 +++++++++++++-------- 6 files changed, 18 insertions(+), 13 deletions(-) diff --git a/README-es.md b/README-es.md index 8dcee184..3397c592 100644 --- a/README-es.md +++ b/README-es.md @@ -132,7 +132,7 @@ Para más información: [debian/conf/nginx.conf](https://salsa.debian.org/nginx- La UI de Nginx está disponible en las siguientes plataformas: -- Mac OS X 10.10 Yosemite y posterior (amd64 / arm64) +- macOS 11 Big Sur y posterior (amd64 / arm64) - Linux 2.6.23 and later (x86 / amd64 / arm64 / armv5 / armv6 / armv7) - Incluyendo pero no limitado a Debian 7 / 8, Ubuntu 12.04 / 14.04 and later, CentOS 6 / 7, Arch Linux - FreeBSD diff --git a/README-vi_VN.md b/README-vi_VN.md index c697ef76..89de1b01 100644 --- a/README-vi_VN.md +++ b/README-vi_VN.md @@ -146,7 +146,7 @@ http { Giao diện người dùng Nginx có sẵn trên các nền tảng sau: -- Mac OS X 10.10 Yosemite and later (amd64 / arm64) +- macOS 11 Big Sur and later (amd64 / arm64) - Linux 2.6.23 and later (x86 / amd64 / arm64 / armv5 / armv6 / armv7) - Bao gồm nhưng không giới hạn Debian 7/8, Ubuntu 12.04/14.04 trở lên, CentOS 6/7, Arch Linux - FreeBSD diff --git a/README-zh_CN.md b/README-zh_CN.md index 2539c49e..23bb9fb0 100644 --- a/README-zh_CN.md +++ b/README-zh_CN.md @@ -125,7 +125,7 @@ http { Nginx UI 可在以下平台中使用: -- Mac OS X 10.10 Yosemite 及之后版本(amd64 / arm64) +- macOS 11 Big Sur 及之后版本(amd64 / arm64) - Linux 2.6.23 及之后版本(x86 / amd64 / arm64 / armv5 / armv6 / armv7) - 包括但不限于 Debian 7 / 8、Ubuntu 12.04 / 14.04 及后续版本、CentOS 6 / 7、Arch Linux - FreeBSD diff --git a/README-zh_TW.md b/README-zh_TW.md index cb2d9e93..028e6b76 100644 --- a/README-zh_TW.md +++ b/README-zh_TW.md @@ -128,7 +128,7 @@ http { Nginx UI 可在以下作業系統中使用: -- Mac OS X 10.10 Yosemite 及之後版本(amd64 / arm64) +- macOS 11 Big Sur 及之後版本(amd64 / arm64) - Linux 2.6.23 及之後版本(x86 / amd64 / arm64 / armv5 / armv6 / armv7) - 包括但不限於 Debian 7 / 8、Ubuntu 12.04 / 14.04 及後續版本、CentOS 6 / 7、Arch Linux - FreeBSD diff --git a/README.md b/README.md index 762c0b23..614d5ae9 100644 --- a/README.md +++ b/README.md @@ -140,7 +140,7 @@ For more information: [debian/conf/nginx.conf](https://salsa.debian.org/nginx-te Nginx UI is available on the following platforms: -- Mac OS X 10.10 Yosemite and later (amd64 / arm64) +- macOS 11 Big Sur and later (amd64 / arm64) - Linux 2.6.23 and later (x86 / amd64 / arm64 / armv5 / armv6 / armv7) - Including but not limited to Debian 7 / 8, Ubuntu 12.04 / 14.04 and later, CentOS 6 / 7, Arch Linux - FreeBSD diff --git a/router/proxy.go b/router/proxy.go index 67990312..8cdb7e76 100644 --- a/router/proxy.go +++ b/router/proxy.go @@ -27,8 +27,8 @@ func proxy() gin.HandlerFunc { defer c.Abort() env := query.Environment - environment, err := env.Where(env.ID.Eq(id)).First() + environment, err := env.Where(env.ID.Eq(id)).First() if err != nil { logger.Error(err) c.AbortWithStatusJSON(http.StatusServiceUnavailable, gin.H{ @@ -37,8 +37,7 @@ func proxy() gin.HandlerFunc { return } - u, err := url.JoinPath(environment.URL, c.Request.RequestURI) - + baseUrl, err := url.Parse(environment.URL) if err != nil { logger.Error(err) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{ @@ -47,8 +46,7 @@ func proxy() gin.HandlerFunc { return } - decodedUri, err := url.QueryUnescape(u) - + proxyUrl, err := baseUrl.Parse(c.Request.RequestURI) if err != nil { logger.Error(err) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{ @@ -57,18 +55,25 @@ func proxy() gin.HandlerFunc { return } - logger.Debug("Proxy request", decodedUri) + logger.Debug("Proxy request", proxyUrl.String()) client := http.Client{ Transport: &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, }, } - req, err := http.NewRequest(c.Request.Method, decodedUri, c.Request.Body) + req, err := http.NewRequest(c.Request.Method, proxyUrl.String(), c.Request.Body) + if err != nil { + logger.Error(err) + c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{ + "message": err.Error(), + }) + return + } + req.Header.Set("X-Node-Secret", environment.Token) resp, err := client.Do(req) - if err != nil { logger.Error(err) c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{