Skip to content

feat(jwt): add token revocation - #1414

Open
maniaba wants to merge 8 commits into
codeigniter4:developfrom
maniaba:feat/jwt-revocation
Open

maniaba wants to merge 8 commits into
codeigniter4:developfrom
maniaba:feat/jwt-revocation

Conversation

@maniaba

@maniaba maniaba commented Nov 24, 2026 •

Copy link
Copy Markdown

Summary

Applications need a way to end API access before an issued JWT expires. This change lets an application revoke the JWT presented at logout. The Shield JWT filter rejects that token on later requests while other tokens issued to the same user remain valid.

  • Generate a unique jti at issuance when the caller omits it and add JWTManager::revokeToken() for a signed, unexpired token.
  • Store a digest of the signed issuer and token ID with its expiration in a table registered in Config\Auth::$tables.
  • Check the revocation table after verifying the JWT. Authentication fails if the revocation lookup fails.
  • Document the migration, an application-owned API logout route, the additional lookup, and scheduled cleanup via JWTManager::purgeExpiredRevocations().

Compatibility

Apply the migration before serving JWT traffic with the new release. Existing JWTs without jti remain usable under the existing signature and time checks. Clients holding those tokens need a newly issued JWT to use the logout endpoint.

Audit logging uses Shield's existing token identifier column. Databases that enforce its 255-character limit can reject log entries for longer JWTs when a token check fails.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@michalsn michalsn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't reviewed the implementation in detail yet, but at first glance, making revocation checks mandatory for all newly issued JWTs seems to impose a single model on applications that may deliberately prefer short-lived access tokens with a separate refresh token mechanism. Although the initial commit describes the feature as "opt-in", there doesn't appear to be a configuration option to disable these checks.

I think revocation support would be a useful addition, but applications should be able to choose whether to enable it. I'd be interested to hear what others think.

@maniaba

maniaba commented Nov 26, 2026 •

Copy link
Copy Markdown
Author

Thanks for raising this, @michalsn.

I originally made revocation configurable with public bool $revocationEnabled = true;, but removed it because I consider the ability to immediately revoke issued tokens a fundamental security feature of an authentication framework.

Short-lived access tokens and revocation are not mutually exclusive. Existing JWTs without a jti also remain valid until they expire, ensuring backward compatibility.

That said, I understand the importance of flexibility in an open-source project and am open to restoring the configuration option, with revocation enabled by default.

I'd be interested to hear what others think.

@maniaba maniaba closed this Nov 26, 2026
@maniaba maniaba reopened this Nov 26, 2026

This branch has not been deployed

No deployments
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.

2 participants