git.iko.soy/typeable/oauth2-proxy
on master help sign in
Validate cookie name (#278)

Validate cookie name passes go's isCookieNameValid check

commitc0150759968e543930a6e0dd30b3419ee29da988 authortanuck <tanuck@gmail.com> dateTue 19 Jul 2016, 20:51 (10 years ago) parent17f412e
2 files changed+25
options.go+10 options_test.go+15
options.go+10
@@ -4,6 +4,7 @@ import (
44 "crypto"
55 "encoding/base64"
66 "fmt"
7+ "net/http"
78 "net/url"
89 "os"
910 "regexp"
@@ -200,6 +201,7 @@ func (o *Options) Validate() error {
200201 }
201202
202203 msgs = parseSignatureKey(o, msgs)
204+ msgs = validateCookieName(o, msgs)
203205
204206 if len(msgs) != 0 {
205207 return fmt.Errorf("Invalid configuration:\n %s",
@@ -261,6 +263,14 @@ func parseSignatureKey(o *Options, msgs []string) []string {
261263 return msgs
262264}
263265
266+func validateCookieName(o *Options, msgs []string) []string {
267+ cookie := &http.Cookie{Name: o.CookieName}
268+ if cookie.String() == "" {
269+ return append(msgs, fmt.Sprintf("invalid cookie name: %q", o.CookieName))
270+ }
271+ return msgs
272+}
273+
264274func addPadding(secret string) string {
265275 padding := len(secret) % 4
266276 switch padding {
options_test.go+15
@@ -2,6 +2,7 @@ package main
22
33import (
44 "crypto"
5+ "fmt"
56 "net/url"
67 "strings"
78 "testing"
@@ -216,3 +217,17 @@ func TestValidateSignatureKeyUnsupportedAlgorithm(t *testing.T) {
216217 assert.Equal(t, err.Error(), "Invalid configuration:\n"+
217218 " unsupported signature hash algorithm: "+o.SignatureKey)
218219}
220+
221+func TestValidateCookie(t *testing.T) {
222+ o := testOptions()
223+ o.CookieName = "_valid_cookie_name"
224+ assert.Equal(t, nil, o.Validate())
225+}
226+
227+func TestValidateCookieBadName(t *testing.T) {
228+ o := testOptions()
229+ o.CookieName = "_bad_cookie_name{}"
230+ err := o.Validate()
231+ assert.Equal(t, err.Error(), "Invalid configuration:\n"+
232+ fmt.Sprintf(" invalid cookie name: %q", o.CookieName))
233+}