Merge SEC-08: atomic system token issuance
This commit is contained in:
@@ -72,16 +72,15 @@ func (ts *tokenServiceServer) IssueServiceToken(ctx context.Context, req *mciasv
|
||||
return nil, status.Error(codes.Internal, "internal error")
|
||||
}
|
||||
|
||||
// Revoke existing system token if any.
|
||||
// Atomically revoke existing system token (if any), track the new token,
|
||||
// and update system_tokens — all in a single transaction.
|
||||
// Security: prevents inconsistent state if a crash occurs mid-operation.
|
||||
var oldJTI string
|
||||
existing, err := ts.s.db.GetSystemToken(acct.ID)
|
||||
if err == nil && existing != nil {
|
||||
_ = ts.s.db.RevokeToken(existing.JTI, "rotated")
|
||||
oldJTI = existing.JTI
|
||||
}
|
||||
|
||||
if err := ts.s.db.TrackToken(claims.JTI, acct.ID, claims.IssuedAt, claims.ExpiresAt); err != nil {
|
||||
return nil, status.Error(codes.Internal, "internal error")
|
||||
}
|
||||
if err := ts.s.db.SetSystemToken(acct.ID, claims.JTI, claims.ExpiresAt); err != nil {
|
||||
if err := ts.s.db.IssueSystemToken(oldJTI, claims.JTI, acct.ID, claims.IssuedAt, claims.ExpiresAt); err != nil {
|
||||
return nil, status.Error(codes.Internal, "internal error")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user