mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-18 16:26:38 +00:00
Strip session_token on redirect
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -124,7 +125,8 @@ func (mw *Middleware) Protect(next http.Handler) http.Handler {
|
|||||||
if cd := proxy.CapturedDataFromContext(r.Context()); cd != nil {
|
if cd := proxy.CapturedDataFromContext(r.Context()); cd != nil {
|
||||||
cd.SetOrigin(proxy.OriginAuth)
|
cd.SetOrigin(proxy.OriginAuth)
|
||||||
}
|
}
|
||||||
http.Redirect(w, r, r.URL.RequestURI(), http.StatusSeeOther)
|
redirectURL := stripSessionTokenParam(r.URL)
|
||||||
|
http.Redirect(w, r, redirectURL, http.StatusSeeOther)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
methods[scheme.Type().String()] = promptData
|
methods[scheme.Type().String()] = promptData
|
||||||
@@ -173,3 +175,16 @@ func (mw *Middleware) RemoveDomain(domain string) {
|
|||||||
defer mw.domainsMux.Unlock()
|
defer mw.domainsMux.Unlock()
|
||||||
delete(mw.domains, domain)
|
delete(mw.domains, domain)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// stripSessionTokenParam returns the request URI with the session_token query
|
||||||
|
// parameter removed so it doesn't linger in the browser's address bar or history.
|
||||||
|
func stripSessionTokenParam(u *url.URL) string {
|
||||||
|
q := u.Query()
|
||||||
|
if !q.Has("session_token") {
|
||||||
|
return u.RequestURI()
|
||||||
|
}
|
||||||
|
q.Del("session_token")
|
||||||
|
clean := *u
|
||||||
|
clean.RawQuery = q.Encode()
|
||||||
|
return clean.RequestURI()
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user