10 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options"
11 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/encryption"
14func validateCookie(o options.Cookie) []string {
15 msgs := validateCookieSecret(o.Secret, o.SecretFile)
17 if o.Expire != time.Duration(0) && o.Refresh >= o.Expire {
18 msgs = append(msgs, fmt.Sprintf(
19 "cookie_refresh (%q) must be less than cookie_expire (%q)",
25 case "", "none", "lax", "strict":
27 msgs = append(msgs, fmt.Sprintf("cookie_samesite (%q) must be one of ['', 'lax', 'strict', 'none']", o.SameSite))
30 // Sort cookie domains by length, so that we try longer (and more specific) domains first
31 sort.Slice(o.Domains, func(i, j int) bool {
32 return len(o.Domains[i]) > len(o.Domains[j])
35 msgs = append(msgs, validateCookieName(o.Name)...)
39func validateCookieName(name string) []string {
42 cookie := &http.Cookie{Name: name}
43 if cookie.String() == "" {
44 msgs = append(msgs, fmt.Sprintf("invalid cookie name: %q", name))
48 msgs = append(msgs, fmt.Sprintf("cookie name should be under 256 characters: cookie name is %d characters", len(name)))
53func validateCookieSecret(secret string, secretFile string) []string {
54 if secret == "" && secretFile == "" {
55 return []string{"missing setting: cookie-secret or cookie-secret-file"}
57 if secret == "" && secretFile != "" {
58 fileData, err := os.ReadFile(secretFile)
60 return []string{"could not read cookie secret file: " + secretFile}
62 // Validate the file content as a secret
63 secretBytes := encryption.SecretBytes(string(fileData))
64 switch len(secretBytes) {
66 // Valid secret size found
69 // Invalid secret size found, return a message
70 return []string{fmt.Sprintf(
71 "cookie_secret from file must be 16, 24, or 32 bytes to create an AES cipher, but is %d bytes",
76 secretBytes := encryption.SecretBytes(secret)
77 // Check if the secret is a valid length
78 switch len(secretBytes) {
80 // Valid secret size found
83 // Invalid secret size found, return a message
84 return []string{fmt.Sprintf(
85 "cookie_secret must be 16, 24, or 32 bytes to create an AES cipher, but is %d bytes",
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list