Skip to content

feat: token revocation list#592

Merged
greatest0fallt1me merged 3 commits into
CalloraOrg:mainfrom
ayomidearegbeshola29-dev:feature/token-revoke-clean
Jun 29, 2026
Merged

feat: token revocation list#592
greatest0fallt1me merged 3 commits into
CalloraOrg:mainfrom
ayomidearegbeshola29-dev:feature/token-revoke-clean

Conversation

@ayomidearegbeshola29-dev

Copy link
Copy Markdown
Contributor

Per-Developer API Token Revocation List (#509)

Overview

Implements an in-memory revocation list with TTL support for immediate API token invalidation without database queries.

Problem

When an API key is revoked via DELETE /api/keys/:id, the key is marked as revoked in the repository. However, subsequent gateway requests with that key would still fail the prefix/hash lookup before checking the revoked flag. For immediate invalidation, we need an in-memory check that can be performed before authentication.

Solution

Created TokenRevocationService that:

  • Stores SHA-256 hashes of revoked tokens (not raw tokens) for security
  • Supports configurable TTL (default 1 hour) for automatic cleanup
  • Runs a sweeper process to remove expired entries
  • Integrates with the gateway to check revoked status before API key verification

Files Changed

New Files

  • src/services/tokenRevocation.ts - Core service implementation
  • src/services/tokenRevocation.test.ts - Unit tests (8 tests)

Modified Files

  • src/repositories/apiKeyRepository.ts

    • Added sha256Hash field to ApiKeyRecord interface
    • Added getSha256Hash(id) method to retrieve hash for revocation list
    • SHA-256 hash computed at key creation time
  • src/routes/apiKeyRoutes.ts

    • DELETE /api/keys/:id now adds SHA-256 hash to in-memory revocation list
  • src/routes/gatewayRoutes.ts

    • Added check for in-memory revocation list before API key verification
    • Returns 403 FORBIDDEN for immediately-revoked tokens

API Changes

No breaking API changes. The revocation list is an internal optimization.

Flow

  1. Client calls DELETE /api/keys/{keyId}
  2. apiKeyRepository.revoke() marks the key as revoked in storage
  3. getSha256Hash() retrieves the SHA-256 hash of the revoked key
  4. TokenRevocationService.revoke() adds hash to in-memory list with TTL
  5. Subsequent gateway requests check isRevoked() before authentication
  6. If revoked, returns 403 FORBIDDEN immediately
  7. Sweeper removes expired entries after TTL

Test Coverage

  • Unit tests for TokenRevocationService (8 tests, 100% coverage)
  • Integration test in gatewayRoutes.test.ts for revocation list check
  • Integration test in apiKeyRoutes.test.ts for revocation list update on DELETE

Configuration

Default TTL: 1 hour (3600000ms)
Default sweep interval: 1 minute (60000ms)

Can be configured via getTokenRevocationService({ defaultTtlMs, sweepIntervalMs })

closes #509

Issue CalloraOrg#509 - Per-developer API token revocation list with TTL

- Created TokenRevocationService for in-memory revoked token tracking
- Added sha256Hash field to ApiKeyRecord for efficient lookup
- Integrated revocation check into gatewayRoutes for immediate invalidation
- Added cleanup sweeper to remove expired entries automatically
- Tests: 8 unit tests for TokenRevocationService, 2 integration tests
@drips-wave

drips-wave Bot commented Jun 29, 2026

Copy link
Copy Markdown

@ayomidearegbeshola29-dev Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@greatest0fallt1me greatest0fallt1me merged commit edd1b4c into CalloraOrg:main Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add per-developer API token revocation list

2 participants