mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-24 14:37:12 +02:00
Fix StripPomeriumCookie
This commit is contained in:
parent
2d2f314a7b
commit
7723b8db6c
2 changed files with 8 additions and 3 deletions
|
@ -32,12 +32,12 @@ func SignRequest(signer cryptutil.JWTSigner, id, email, groups, header string) f
|
||||||
func StripPomeriumCookie(cookieName string) func(next http.Handler) http.Handler {
|
func StripPomeriumCookie(cookieName string) func(next http.Handler) http.Handler {
|
||||||
return func(next http.Handler) http.Handler {
|
return func(next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx, span := trace.StartSpan(r.Context(), "middleware.SignRequest")
|
ctx, span := trace.StartSpan(r.Context(), "middleware.StripPomeriumCookie")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
headers := make([]string, len(r.Cookies()))
|
headers := make([]string, 0, len(r.Cookies()))
|
||||||
for _, cookie := range r.Cookies() {
|
for _, cookie := range r.Cookies() {
|
||||||
if cookie.Name != cookieName {
|
if !strings.HasPrefix(cookie.Name, cookieName) {
|
||||||
headers = append(headers, cookie.String())
|
headers = append(headers, cookie.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,6 +84,11 @@ func TestStripPomeriumCookie(t *testing.T) {
|
||||||
Name: tt.pomeriumCookie,
|
Name: tt.pomeriumCookie,
|
||||||
Value: "pomerium cookie!",
|
Value: "pomerium cookie!",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
http.SetCookie(rr, &http.Cookie{
|
||||||
|
Name: tt.pomeriumCookie + "_csrf",
|
||||||
|
Value: "pomerium csrf cookie!",
|
||||||
|
})
|
||||||
req := &http.Request{Header: http.Header{"Cookie": rr.Header()["Set-Cookie"]}}
|
req := &http.Request{Header: http.Header{"Cookie": rr.Header()["Set-Cookie"]}}
|
||||||
|
|
||||||
handler := StripPomeriumCookie(tt.pomeriumCookie)(testHandler)
|
handler := StripPomeriumCookie(tt.pomeriumCookie)(testHandler)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue