Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Commit

Permalink
Merge pull request from GHSA-5v95-v8c8-3rh6
Browse files Browse the repository at this point in the history
This fixes a security vulnerability where, with a carefully crafted request or malicious proxy, a user with UserWrite permissions could create another user with higher privileges than their own due to insufficient checks on the allowed set of permissions.
  • Loading branch information
sethvargo committed Mar 15, 2021
1 parent 3d28d0b commit eb8cf40
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/rbac/rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ func Can(given Permission, target Permission) bool {
func CompileAndAuthorize(actorPermission Permission, toUpdate []Permission) (Permission, error) {
var permission Permission
for _, update := range toUpdate {
// Verify the provided permission is a known permission. This prevents a
// security vulnerability whereby a carefully crafted request is able to
// provide a value that correctly passes an the bitwise AND check and then
// modifies the target permission using OR to escalate privilege.
if _, ok := PermissionMap[update]; !ok {
if update != LegacyRealmAdmin && update != LegacyRealmUser {
return 0, fmt.Errorf("provided permission %v is unknown", update)
}
}

// Verify that the user making changes has the permissions they are trying
// to grant. It is not valid for someone to grant permissions larger than
// they currently have.
Expand Down
24 changes: 24 additions & 0 deletions pkg/rbac/rbac_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,30 @@ func TestRequiredPermissions(t *testing.T) {
t.Errorf("expected error")
}
})

t.Run("legacy_admin", func(t *testing.T) {
t.Parallel()

if _, err := CompileAndAuthorize(LegacyRealmAdmin, []Permission{LegacyRealmAdmin}); err != nil {
t.Error(err)
}
})

t.Run("legacy_user", func(t *testing.T) {
t.Parallel()

if _, err := CompileAndAuthorize(LegacyRealmAdmin, []Permission{LegacyRealmUser}); err != nil {
t.Error(err)
}
})

t.Run("escalate", func(t *testing.T) {
t.Parallel()

if _, err := CompileAndAuthorize(UserRead|UserWrite, []Permission{16383}); err == nil {
t.Errorf("expected error")
}
})
}

func TestImpliedBy(t *testing.T) {
Expand Down

0 comments on commit eb8cf40

Please # to comment.