-
Notifications
You must be signed in to change notification settings - Fork 579
/
cookie.go
34 lines (30 loc) · 877 Bytes
/
cookie.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package httpapi
import (
"net/textproto"
"strings"
"github.com/coder/coder/v2/codersdk"
)
// StripCoderCookies removes the session token from the cookie header provided.
func StripCoderCookies(header string) string {
header = textproto.TrimString(header)
cookies := []string{}
var part string
for len(header) > 0 { // continue since we have rest
part, header, _ = strings.Cut(header, ";")
part = textproto.TrimString(part)
if part == "" {
continue
}
name, _, _ := strings.Cut(part, "=")
if name == codersdk.SessionTokenCookie ||
name == codersdk.OAuth2StateCookie ||
name == codersdk.OAuth2RedirectCookie ||
name == codersdk.PathAppSessionTokenCookie ||
name == codersdk.SubdomainAppSessionTokenCookie ||
name == codersdk.SignedAppTokenCookie {
continue
}
cookies = append(cookies, part)
}
return strings.Join(cookies, "; ")
}