Skip to content

Server edition: bearer-JWT admin role is trusted from the frozen claim, so admin demotion does not take effect until the token expires #1169

Closed

Description

@Dumbris

Summary

The two auth paths in internal/serveredition/auth/middleware.go derive the admin role differently, and only one of them re-checks the current configuration.

Session path (middleware.go:130, buildAuthContext at :180-185) calls m.teamsConfig.IsAdminEmail(user.Email) on every request.

Bearer-JWT path (middleware.go:172-175) takes the role verbatim from the token claim:

if claims.Role == "admin" {
    return coreauth.AdminUserContext(claims.Subject, claims.Email, claims.DisplayName, claims.Provider), nil
}

It re-validates that the user still exists and is not Disabled (lines 158-169) — but not their role.

Impact

Removing an address from admin_emails does not take effect for anyone holding a JWT minted while they were an admin. They keep full admin access — every AdminOnly() route, and CanRevealSecrets() — until the token expires (session_ttl, default 24h). Disabling the account does work, so the workaround exists; demotion-without-disabling is the gap.

Suggested fix

Re-derive the role on the bearer path the way the session path does — call buildAuthContext(user) after the existence/disabled checks rather than branching on claims.Role. The user record is already loaded at that point, so there is no extra lookup.

Severity is moderate: it needs a prior admin whose privilege was revoked, and it self-heals at token expiry.

Found during the #1161 residual sweep (#1165); out of scope there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/teamskind/bugkind/security

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions