outposts/proxy: Fix invalid redirect on external hosts containing path components (#8915)
* outposts/proxy: Fix invalid redirect on external hosts containing path components Signed-off-by: Max <github@germancoding.com> * outposts/proxy: Fix test for changed redirect logic Signed-off-by: Max <github@germancoding.com> --------- Signed-off-by: Max <github@germancoding.com>
This commit is contained in:
@ -3,7 +3,6 @@ package application
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@ -11,22 +10,12 @@ import (
|
||||
"goauthentik.io/internal/outpost/proxyv2/constants"
|
||||
)
|
||||
|
||||
func urlPathSet(originalUrl string, newPath string) string {
|
||||
u, err := url.Parse(originalUrl)
|
||||
if err != nil {
|
||||
return originalUrl
|
||||
}
|
||||
u.Path = newPath
|
||||
return u.String()
|
||||
}
|
||||
|
||||
func urlJoin(originalUrl string, newPath string) string {
|
||||
u, err := url.Parse(originalUrl)
|
||||
u, err := url.JoinPath(originalUrl, newPath)
|
||||
if err != nil {
|
||||
return originalUrl
|
||||
}
|
||||
u.Path = path.Join(u.Path, newPath)
|
||||
return u.String()
|
||||
return u
|
||||
}
|
||||
|
||||
func (a *Application) redirectToStart(rw http.ResponseWriter, r *http.Request) {
|
||||
@ -46,7 +35,7 @@ func (a *Application) redirectToStart(rw http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
redirectUrl := urlPathSet(a.proxyConfig.ExternalHost, r.URL.Path)
|
||||
redirectUrl := urlJoin(a.proxyConfig.ExternalHost, r.URL.Path)
|
||||
|
||||
if a.Mode() == api.PROXYMODE_FORWARD_DOMAIN {
|
||||
dom := strings.TrimPrefix(*a.proxyConfig.CookieDomain, ".")
|
||||
|
Reference in New Issue
Block a user