Skip to content

Commit

Permalink
#104 and #109 large cookies full of tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
bnfinet committed May 22, 2019
1 parent 789ac29 commit dba94fe
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
9 changes: 9 additions & 0 deletions config/config.yml_example
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ vouch:
querystring: access_token
redirect: X-Vouch-Requested-URI

# GENERAL WARNING ABOUT claims AND tokens
# all of these config elements can cause performance impacts due to the amount of information being
# moved around. They will get added to the Vouch cookie and (possibly) make it large. The Vouch cookie will
# get split up into several cookies. Every request will process the cookies in order to extract and create the
# additional headers which get returned. But if you need it, you need it.
# With large cookies and headers it will require additional nginx config to open up the buffers a bit..
# see `large_client_header_buffers` http://nginx.org/en/docs/http/ngx_http_core_module.html#large_client_header_buffers
# and `proxy_buffer_size` http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_buffer_size

# claims - a list of claims that will be stored in the JWT and passed down to applications via headers
# By default claims are sent down as headers with a prefix of X-Vouch-IdP-Claims-ClaimKey
# Only when a claim is found in the user's info will the header exist. This is optional. These are case sensitive.
Expand Down
7 changes: 5 additions & 2 deletions handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ func ValidateRequestHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Add(cfg.Cfg.Headers.User, claims.Username)
w.Header().Add(cfg.Cfg.Headers.Success, "true")

log.Debugf("response header %+v", w.Header())
if cfg.Cfg.Headers.AccessToken != "" {
if claims.PAccessToken != "" {
w.Header().Add(cfg.Cfg.Headers.AccessToken, claims.PAccessToken)
Expand All @@ -240,8 +239,11 @@ func ValidateRequestHandler(w http.ResponseWriter, r *http.Request) {

}
}
// fastlog.Debugf("response headers %+v", w.Header())
// fastlog.Debug("response header",
// zap.String(cfg.Cfg.Headers.User, w.Header().Get(cfg.Cfg.Headers.User)))
fastlog.Debug("response header",
zap.String(cfg.Cfg.Headers.User, w.Header().Get(cfg.Cfg.Headers.User)))
zap.Any("all headers", w.Header()))

// good to go!!
if cfg.Cfg.Testing {
Expand Down Expand Up @@ -523,6 +525,7 @@ func getUserInfo(r *http.Request, user *structs.User, customClaims *structs.Cust
}
ptokens.PAccessToken = providerToken.AccessToken
ptokens.PIdToken = providerToken.Extra("id_token").(string)
log.Debugf("ptokens: %+v", ptokens)

// make the "third leg" request back to google to exchange the token for the userinfo
client := cfg.OAuthClient.Client(context.TODO(), providerToken)
Expand Down
5 changes: 3 additions & 2 deletions pkg/cookie/cookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func setCookie(w http.ResponseWriter, r *http.Request, val string, maxAge int) {
func Cookie(r *http.Request) (string, error) {

var cookieParts []string
var numParts int = -1
var numParts = -1

var err error
cookies := r.Cookies()
Expand All @@ -102,13 +102,14 @@ func Cookie(r *http.Request) (string, error) {
if numParts, err = strconv.Atoi(xyArray[1]); err != nil {
return "", fmt.Errorf("multipart cookie fail: %s", err)
}
log.Debugf("make cookieParts of size %d", numParts)
cookieParts = make([]string, numParts)
}
var i int
if i, err = strconv.Atoi(xyArray[0]); err != nil {
return "", fmt.Errorf("multipart cookie fail: %s", err)
}
cookieParts[i] = cookie.Value
cookieParts[i-1] = cookie.Value
}

}
Expand Down

0 comments on commit dba94fe

Please sign in to comment.