Skip to content

Commit 1b7d6d3

Browse files
committed
changes following review
1 parent 54d03fb commit 1b7d6d3

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

internal/pkg/validators/email_group_validator.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package validators
22

33
import (
44
"errors"
5+
"fmt"
56

67
"github.com/buzzfeed/sso/internal/pkg/sessions"
78
"github.com/buzzfeed/sso/internal/proxy/providers"
@@ -10,7 +11,7 @@ import (
1011
var (
1112
_ Validator = EmailGroupValidator{}
1213

13-
// These error message should be formatted in such a way that is appropriate
14+
// These error messages should be formatted in such a way that is appropriate
1415
// for display to the end user.
1516
ErrGroupMembership = errors.New("Invalid Group Membership")
1617
)
@@ -50,5 +51,5 @@ func (v EmailGroupValidator) validate(session *sessions.SessionState) error {
5051
return nil
5152
}
5253

53-
return ErrGroupMembership
54+
return fmt.Errorf("%v. Allowed Groups: %q", ErrGroupMembership, v.AllowedGroups)
5455
}

internal/proxy/oauthproxy.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,7 @@ func (p *OAuthProxy) runValidatorsWithGracePeriod(session *sessions.SessionState
388388
return err
389389
}
390390
}
391-
allowedGroups := p.upstreamConfig.AllowedGroups
392-
logger.WithUser(session.Email).WithAllowedGroups(allowedGroups).Error(errors,
391+
logger.WithUser(session.Email).Error(errors,
393392
"no longer authorized after validation period")
394393
return ErrUserNotAuthorized
395394
}
@@ -610,7 +609,11 @@ func (p *OAuthProxy) OAuthCallback(rw http.ResponseWriter, req *http.Request) {
610609
logger.WithRemoteAddress(remoteAddr).WithUser(session.Email).WithInGroups(session.Groups).Info(
611610
fmt.Sprintf("oauth callback: user validated "))
612611

613-
//TODO: is there any verification we want to do on this?
612+
// We add the request host into the session to allow us to validate that each request has
613+
// been authorized for the upstream it's requesting.
614+
// e.g. if a request is authenticated while trying to reach 'foo' upstream, it should not
615+
// automatically be seen as authorized with 'bar' upstream. Each upstream may set different
616+
// validators, so the request should be reauthenticated.
614617
session.AuthorizedUpstream = req.Host
615618

616619
// We store the session in a cookie and redirect the user back to the application
@@ -807,6 +810,8 @@ func (p *OAuthProxy) Authenticate(rw http.ResponseWriter, req *http.Request) (er
807810
// - call up the provider chain to validate this user is still active and hasn't been de-authorized.
808811
// - run any defined email domain, email address, and email group validators against the session
809812

813+
//TODO: change this to match the RefreshSessionToken
814+
// (https://github.com/buzzfeed/sso/pull/275#discussion_r366448883)
810815
ok := p.provider.ValidateSessionToken(session)
811816
if !ok {
812817
// This user is now no longer authorized, or we failed to

0 commit comments

Comments
 (0)