-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathcookie.go
More file actions
38 lines (34 loc) · 1.09 KB
/
cookie.go
File metadata and controls
38 lines (34 loc) · 1.09 KB
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
35
36
37
38
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 ||
// This uses a prefix check because the subdomain cookie is unique
// per workspace proxy and is based on a hash of the workspace proxy
// subdomain hostname. See the workspaceapps package for more
// details.
strings.HasPrefix(name, codersdk.SubdomainAppSessionTokenCookie) ||
name == codersdk.SignedAppTokenCookie {
continue
}
cookies = append(cookies, part)
}
return strings.Join(cookies, "; ")
}