Skip to content

Commit

Permalink
Make state encoding signatures consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Meves committed Feb 20, 2021
1 parent 6414933 commit 53dc04c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
6 changes: 3 additions & 3 deletions oauthproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ func (p *OAuthProxy) OAuthStart(rw http.ResponseWriter, req *http.Request) {
callbackRedirect := p.getOAuthRedirectURI(req)
loginURL := p.provider.GetLoginURL(
callbackRedirect,
encodeState(csrf, appRedirect),
encodeState(csrf.HashOAuthState(), appRedirect),
csrf.HashOIDCNonce(),
)

Expand Down Expand Up @@ -1109,8 +1109,8 @@ func extractAllowedGroups(req *http.Request) map[string]struct{} {

// encodedState builds the OAuth state param out of our nonce and
// original application redirect
func encodeState(csrf cookies.CSRF, redirect string) string {
return fmt.Sprintf("%v:%v", csrf.HashOAuthState(), redirect)
func encodeState(nonce string, redirect string) string {
return fmt.Sprintf("%v:%v", nonce, redirect)
}

// decodeState splits the reflected OAuth state response back into
Expand Down
5 changes: 4 additions & 1 deletion oauthproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,10 @@ func (patTest *PassAccessTokenTest) getCallbackEndpoint() (httpCode int, cookie

req, err := http.NewRequest(
http.MethodGet,
fmt.Sprintf("/oauth2/callback?code=callback_code&state=%s", encodeState(csrf, "%2F")),
fmt.Sprintf(
"/oauth2/callback?code=callback_code&state=%s",
encodeState(csrf.HashOAuthState(), "%2F"),
),
strings.NewReader(""),
)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/cookies/cookies.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func MakeCookieFromOptions(req *http.Request, name string, value string, opts *o
SameSite: ParseSameSite(opts.SameSite),
}

WarnInvalidDomain(c, req)
warnInvalidDomain(c, req)

return c
}
Expand Down Expand Up @@ -69,9 +69,9 @@ func ParseSameSite(v string) http.SameSite {
}
}

// WarnInvalidDomain logs a warning if the request host and cookie domain are
// warnInvalidDomain logs a warning if the request host and cookie domain are
// mismatched.
func WarnInvalidDomain(c *http.Cookie, req *http.Request) {
func warnInvalidDomain(c *http.Cookie, req *http.Request) {
if c.Domain == "" {
return
}
Expand Down

0 comments on commit 53dc04c

Please sign in to comment.