Skip to content

Commit

Permalink
refactor sso state checks into single function
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Berry <[email protected]>
  • Loading branch information
bengerman13 authored and richard-cox committed May 29, 2020
1 parent 839cc2f commit 28920c0
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions src/jetstream/authuaa.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,14 +435,11 @@ func (p *portalProxy) RefreshUAAToken(userGUID string) (t interfaces.TokenRecord
// We use a single callback so this can be whitelisted in the client
func (p *portalProxy) ssoLoginToUAA(c echo.Context) error {
state := c.QueryParam("state")
if len(state) == 0 {
err := interfaces.NewHTTPShadowError(
http.StatusUnauthorized,
"SSO Login: State parameter missing",
"SSO Login: State parameter missing")
return err
}

stateErr := validateSSORedirectState(state, p.Config.SSOWhiteList)
if stateErr != nil {
return stateErr
}
// We use the same callback URL for both UAA and endpoint login
// Check if it is an endpoint login and dens to the right handler
endpointGUID := c.QueryParam("guid")
Expand All @@ -466,13 +463,6 @@ func (p *portalProxy) ssoLoginToUAA(c echo.Context) error {
state = fmt.Sprintf("%s/login?SSO_Message=%s", state, url.QueryEscape(msg))
}

if !safeSSORedirectState(state, p.Config.SSOWhiteList) {
err := interfaces.NewHTTPShadowError(
http.StatusUnauthorized,
"SSO Login: Disallowed redirect state",
"SSO Login: Disallowed redirect state")
return err
}

return c.Redirect(http.StatusTemporaryRedirect, state)
}
Expand Down Expand Up @@ -527,24 +517,32 @@ func (p *portalProxy) initSSOlogin(c echo.Context) error {
}

state := c.QueryParam("state")
stateErr := validateSSORedirectState(state, p.Config.SSOWhiteList)
if stateErr != nil {
return stateErr
}

redirectURL := fmt.Sprintf("%s/oauth/authorize?response_type=code&client_id=%s&redirect_uri=%s", p.Config.ConsoleConfig.AuthorizationEndpoint, p.Config.ConsoleConfig.ConsoleClient, url.QueryEscape(getSSORedirectURI(state, state, "")))
c.Redirect(http.StatusTemporaryRedirect, redirectURL)
return nil
}

func validateSSORedirectState(state string, whiteListStr string) error {
if len(state) == 0 {
err := interfaces.NewHTTPShadowError(
http.StatusUnauthorized,
"SSO Login: Redirect state parameter missing",
"SSO Login: Redirect state parameter missing")
"SSO Login: State parameter missing",
"SSO Login: State parameter missing")
return err
}

if !safeSSORedirectState(state, p.Config.SSOWhiteList) {
if !safeSSORedirectState(state,whiteListStr) {
err := interfaces.NewHTTPShadowError(
http.StatusUnauthorized,
"SSO Login: Disallowed redirect state",
"SSO Login: Disallowed redirect state")
return err
}

redirectURL := fmt.Sprintf("%s/oauth/authorize?response_type=code&client_id=%s&redirect_uri=%s", p.Config.ConsoleConfig.AuthorizationEndpoint, p.Config.ConsoleConfig.ConsoleClient, url.QueryEscape(getSSORedirectURI(state, state, "")))
c.Redirect(http.StatusTemporaryRedirect, redirectURL)
return nil
}

Expand Down

0 comments on commit 28920c0

Please sign in to comment.