Repository navigation
Releases
v3.1.0
Upgrade if you have hash_tokens enabled. The value stored for a refresh token was accepted as the token itself, so being able to read the table was enough to refresh with any row in it.
Security: the stored hash was accepted as the refresh token
HashedRefreshTokenManager::get() hashes what is presented and looks that up. A value that is already a stored hash cannot match there, because that lookup asks for the hash of a hash, so it fell through to the fallback that keeps tokens issued before hashing was turned on working. That fallback looks the presented value up as it is, and the stored value matches the row holding it. save() then saw the sha256$ prefix and left the row alone, so the same value went on working indefinitely, and with single_use each rotated row was as usable as the one before it.
Reading the table is the one thing hashing exists to survive, so this took the point out of the option entirely. A value in the stored format is now refused before the fallback runs, and not looked up at all: the sha256$ prefix is reserved, and no client is ever given a value carrying it.
Affects 2.2.0, 2.2.1, 2.2.2 and 3.0.0 with hash_tokens enabled. It is not reachable without read access to the stored rows. 2.3.0 carries the same fix for the 2.x line.
If you cannot upgrade right away, this closes the only way in, on every affected version:
gesdinet_jwt_refresh_token:
hash_tokens:
enabled: true
accept_stored_in_the_clear: falseThat also stops accepting tokens issued before hashing was turned on, so any session still holding one is signed out.
Reported privately by Rathnadeepan (HotWater), who also proposed the fix taken here. A GitHub security advisory is being filed.
Clearing expired tokens without reading them first
revokeAllInvalid() and revokeAllInvalidBatch() hydrate every token they delete, because they hand them back and the object manager wants the objects to remove them. That is what lets gesdinet:jwt:clear list what it revoked and what raises the life-cycle events an application may be listening for, and it costs one object per dead row. Clearing a table that has grown for months is the one thing the command was bad at.
Model\ExpiredRefreshTokenManagerInterface::revokeAllExpired() sends a single statement instead, so what it costs no longer grows with the backlog:
use Gesdinet\JWTRefreshTokenBundle\Model\ExpiredRefreshTokenManagerInterface;
public function __construct(
private ExpiredRefreshTokenManagerInterface $refreshTokenManager,
) {
}
public function clearOut(): int
{
return $this->refreshTokenManager->revokeAllExpired();
}and --direct runs it from the command line:
php bin/console gesdinet:jwt:clear --directThe trade is that the tokens are only counted. Nothing is listed with -v, no life-cycle events are raised, and --batch-size has nothing left to do, which is why it is a flag rather than the new behaviour. Without it the command works exactly as before.
Available with the ORM, ODM and DBAL backends. A repository of your own gains it by implementing Doctrine\DeleteExpiredRefreshTokenRepositoryInterface, and the manager says which interface is missing rather than calling a method that is not there.
The implementation is @Rainrider's, from #432, which he withdrew.
Fixed
reuse_detectionrecorded a spent token under the value the model carries, which is the hash whenhash_tokensis on, while every lookup asks for the value the client sent. Nothing was ever recalled, so the detection was inert, with no error and no log (#433)cache_pool,block_jwts_on_revocation,rate_limiterandreuse_detectioneach took a service id that was referenced as a%parameter%placeholder inside a service id, which Symfony never resolves. Turning any of the four on left the container unable to compile (#434)
Changed
- Requires Symfony 8.1. Every
symfony/http-foundation8.0.x is affected by CVE-2026-108082, fixed only in 8.1.7, so there is no 8.0 left to support
No BC break, and no schema change.
v2.3.0
Upgrade if you have hash_tokens enabled. The value stored for a refresh token was accepted as the token itself, so being able to read the table was enough to refresh with any row in it. This is the 2.x line's fix for it; 3.1.0 carries the same one.
A minor rather than 2.2.3 because it also adds public API. Nothing is deprecated, nothing breaks, and there is no schema change.
Security: the stored hash was accepted as the refresh token
HashedRefreshTokenManager::get() hashes what is presented and looks that up. A value that is already a stored hash cannot match there, because that lookup asks for the hash of a hash, so it fell through to the fallback that keeps tokens issued before hashing was turned on working. That fallback looks the presented value up as it is, and the stored value matches the row holding it. save() then saw the sha256$ prefix and left the row alone, so the same value went on working indefinitely, and with single_use each rotated row was as usable as the one before it.
Reading the table is the one thing hashing exists to survive, so this took the point out of the option entirely. A value in the stored format is now refused before the fallback runs, and not looked up at all: the sha256$ prefix is reserved, and no client is ever given a value carrying it.
Affects 2.2.0, 2.2.1, 2.2.2 and 3.0.0 with hash_tokens enabled. It is not reachable without read access to the stored rows.
If you cannot upgrade right away, this closes the only way in, on every affected version:
gesdinet_jwt_refresh_token:
hash_tokens:
enabled: true
accept_stored_in_the_clear: falseThat also stops accepting tokens issued before hashing was turned on, so any session still holding one is signed out.
Reported privately by Rathnadeepan (HotWater), who also proposed the fix taken here. A GitHub security advisory is being filed.
Clearing expired tokens without reading them first
revokeAllInvalid() and revokeAllInvalidBatch() hydrate every token they delete, because they hand them back and the object manager wants the objects to remove them. That is what lets gesdinet:jwt:clear list what it revoked and what raises the life-cycle events an application may be listening for, and it costs one object per dead row. Clearing a table that has grown for months is the one thing it is bad at.
Model\ExpiredRefreshTokenManagerInterface::revokeAllExpired() sends a single statement instead, so what it costs no longer grows with the backlog:
use Gesdinet\JWTRefreshTokenBundle\Model\ExpiredRefreshTokenManagerInterface;
public function __construct(
private ExpiredRefreshTokenManagerInterface $refreshTokenManager,
) {
}
public function clearOut(): int
{
// Everything that had expired by now. Pass a date to clear what had expired by then instead
return $this->refreshTokenManager->revokeAllExpired();
}The trade is that the tokens are only counted: nothing is hydrated, so no life-cycle events are raised and what went cannot be reported. revokeAllInvalid() and revokeAllInvalidBatch() hand the tokens back and are what an application listening for their removal wants instead.
gesdinet:jwt:clear is unchanged on this branch. The --direct flag that runs this from the command line is in 3.1.0 only, so nothing a maintenance release does changes behind an existing invocation.
Available with the ORM, ODM and DBAL backends. A repository of your own gains it by implementing Doctrine\DeleteExpiredRefreshTokenRepositoryInterface, and the manager says which interface is missing rather than calling a method that is not there.
The implementation is @Rainrider's, from #432, which he withdrew.
v3.0.0
Symfony 8, PHP 8.4 and LexikJWTAuthenticationBundle 3.
This release needs a schema change before the application will run. Refresh tokens gained family and family_valid columns, and Doctrine reads every mapped field.
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrateRead UPGRADE-3.0.md first, and UPGRADE-RECTOR.md if you are coming from further back than 2.2.
If you are on Symfony 6.4 or 7.x, stay on 2.2. It is maintained, and Symfony 7.4 is supported until November 2028.
What a session is now
Refresh tokens belong to a chain. A token issued in place of another carries the family of the one it replaced, so a login and every refresh descending from it share one value — which is what makes a session addressable. Without it, "end this session" can only mean "delete this one token", and with single_use that token has usually already been replaced.
Everything below is built on that, and all of it is off by default.
reuse_detection— recognises a spent token being presented again and revokes the whole chain. Rotation on its own leaves a stolen token working until the legitimate client happens to refresh, and nobody learns why it broke. It cannot tell theft from a client racing itself, so it revokes either way and dispatches an event for the judgement it cannot make.max_session_lifetime— a ceiling on how long a chain may go on for, whateverttlsays.block_jwts_on_revocation— refuses the JWTs already issued to a user whenrevokeAllForUser()takes their refresh tokens away. Lexik's blocklist is keyed byjtiand cannot do this; what is recorded instead is when the revocation happened.SessionLister— the "where you are signed in" screen and the button next to each row, grouped by chain rather than by token.rate_limiter— consumed before the token is looked at, so a refusal costs no query and its timing says nothing about whether the token exists.cache_pool— stores the tokens in a PSR-6 pool, where expiry is the pool's job. It implements only what a pool can honour and says so about the rest.- Per-firewall configuration —
ttl,single_useand the rest on therefresh_jwtauthenticator, which is the longest-standing thing this bundle could not do.
Breaking changes
- PHP 8.4, Symfony 8.0, LexikJWTAuthenticationBundle 3, doctrine/dbal 4
check_pathis required onrefresh_jwtRefreshEventtakes the request, and$firewallNameloses its defaultdbal_columns, when configured, has to name theidcolumn- Nine classes are
final; the token models and repositories are deliberately not
The full list is in the changelog.
v2.2.2
2.2.1 did not actually fix #431 for everyone. If you are on Symfony 7.0, 7.1, 7.2 or 7.3, or on a patch of 6.4 older than 6.4.37 or of 8.0 older than 8.0.9, upgrade to this instead.
What 2.2.1 got wrong
The check on ttl was moved from a validate() closure to min(), because NumericNode skips min() while it is handling the placeholder an environment variable stands in as.
It does — in symfony/config 6.4.37, 7.4.9, 8.0.9 and 8.1 onwards. That skip was backported to the maintained branches only, and 7.0 through 7.3 are end of life, so they never received it and never will. On any of those, 2.2.1 rejected %env(int:...)% exactly as 2.2.0 did.
What this does
Neither ttl nor max_tokens_per_user is validated in the configuration tree any more.
On the affected versions there is no check that can tell the sample value of 0 — which Symfony substitutes to see whether the configuration would accept the variable — from a 0 written by hand. Refusing to boot an application that reads its ttl from the environment is the worse of the two failures, so the check is gone rather than made conditional.
A ttl of 0 or less is therefore accepted again, as it was in 2.1.0 and earlier. It still produces a token that has expired by the time it is handed over, so it is worth not writing one.
gesdinet_jwt_refresh_token:
ttl: '%env(int:JWT_REFRESH_TOKEN_LIFETIME_IN_SECONDS)%'works on every Symfony this release supports.
v2.2.1
Fixes a regression in 2.2.0, reported by @dennismetz in #431.
ttl and max_tokens_per_user from an environment variable
gesdinet_jwt_refresh_token:
ttl: '%env(int:JWT_REFRESH_TOKEN_LIFETIME_IN_SECONDS)%'failed to compile with:
Invalid configuration for path "gesdinet_jwt_refresh_token.ttl":
The "ttl" must be a positive number of seconds, and 0 is not.
An environment variable is a placeholder at compile time, and Symfony compiles the configuration a second time with a sample value of the declared type in its place, to check it would be accepted. For an integer that sample is 0, and the check added in 2.2.0 rejects anything below 1 — so it rejected every integer environment variable, whatever the variable held.
NumericNode skips min() and max() while it is handling a placeholder. A validate() closure is not skipped, which is why the built-in constraint is now used for both nodes. The validation itself is unchanged: 0 and negative values are still rejected when written literally.
2.1.0 is not affected — the ttl check did not exist before 2.2.0.
Only ttl and max_tokens_per_user were affected. default_invalid_batch_size already used min(), and cookie.same_site was fixed for the same underlying reason in 2.2.0.
v2.2.0
Two features for keeping refresh tokens under control, one for documenting them, and a fix that made the recommended configuration work as written.
See UPGRADE-2.2.md before upgrading. One configuration is now rejected; everything else is additive or a correction.
An expired JWT can be exchanged
With jwt and refresh_jwt on the same firewall, the JWT authenticator was reached first and rejected the expired token before the refresh authenticator saw it — so the configuration in the README did not work as written, and the advice given for years, to reorder them on the firewall, could never have helped. Symfony orders authenticators by the priority each factory declares, not by the file. This one now sits above Lexik's.
Nothing to change. Applications that split the refresh endpoint into its own firewall to get around it can collapse it back.
Storing hashes instead of tokens
gesdinet_jwt_refresh_token:
hash_tokens:
enabled: trueA refresh token gets its holder back into an account without a password, so a copy of the table was a copy of everybody's credentials, next to the passwords that are hashed for exactly that reason. What is stored is now sha256$ and the hash, and a leaked table cannot be used.
Off by default, and turning it on signs nobody out: tokens already stored are taken as they are and rewritten hashed the first time they are used. getRefreshToken() then returns the stored hash, which is worth reading about in the upgrade guide first.
A limit on sessions per user
gesdinet_jwt_refresh_token:
max_tokens_per_user: 5Every login stores a token, deliberately, so that a user's devices are separate sessions. Nothing bounded how many accumulated. Signing in beyond the limit revokes the session that has gone longest without being refreshed, expired ones first.
Documented in API Platform
gesdinet_jwt_refresh_token:
api_platform:
enabled: trueLexik documents the login endpoint, but its response schema only carries the JWT, because the refresh token beside it is added by this bundle. The refresh endpoint was documented by nobody, being a firewall authenticator rather than a controller. Both are covered now, from the bundle's own configuration — so with the cookie replacing the body, no refresh_token field is promised that never arrives.
Also
- A DBAL backend (
dbal_connection) storing tokens through a plain connection, with no object manager and no unit of work. refresh_token_managernaming a manager of your own, wiring none of the bundle's storage, so the tokens can live in a PDO repository or anywhere else and Doctrine need not be installed at all.single_use_ttl_update: falseso a token issued in place of a single use one inherits the expiry of the one it replaced, bounding the chain.ListRefreshTokenManagerInterface::findAllForUser()andrevokeAllForUser()for showing a user their sessions and ending them.- One query per refresh instead of two.
- Symfony 7.0 and 7.1 are installable; two components stopped at
^7.2while the rest allowed^7.0, and Composer resolves the intersection. - Fixes to the cookie expiry, logout invalidating somebody else's token, reading the token from a body with no
Content-Type,delete()reporting the rows it actually removed, andcookie.same_sitefrom an environment variable.
The issue tracker is empty as of this release: 64 issues were reviewed and closed, several of them fixed here.
v2.1.0
Fixes across the batch revocation, the MongoDB ODM and the values read from the request. Nothing has to be changed in an application using the bundle through its configuration and its services: see UPGRADE-2.1.md for the return values an application may be reading.
Fixed
revokeAllInvalidBatch()returned the last batch read, which is empty once the loop ends, so it always returned an empty array andgesdinet:jwt:clearreported that there was nothing to revoke after deleting tokensrevokeAllInvalidBatch()looped forever with the MongoDB ODM, as its condition tested the repository result withempty(), which is never true for the iterator the ODM returnsrevokeAllInvalidBatch()skipped expired tokens: each batch is deleted before the next is read, so the remaining tokens shift down and the offset has to stay where it is- The document repository reads its results through
Query::getIterator(), so they are the iterable the interface promises delete()returns0when the token is not in storage, which the ODM reported as1regardless- The success listener no longer brings the request down when a token has no expiration date
- A refresh token without a username is rejected with an
InvalidTokenExceptioninstead of aTypeErrorwhile building the passport refresh_token_classreports a configuration error when the class cannot be loaded, instead of aTypeErrorwhile building the containergesdinet:jwt:clearrejects a--batch-sizethat is not a positive number, which read no tokens and reported success while leaving every expired token in place- Both request extractors check what they read before returning it, and the authentication token checks the serialized state it is given
Changed
AuthenticationSuccessHandler::onAuthenticationSuccess()is typed?Response, matching the handler it decorates. What is returned at runtime has not changedRefreshTokenRepositoryInterfacedocuments, through a@methodtag, thatfindOneBy()takes an optional$orderByargument- The
phpconstraint is written as^8.2, the same minimum without claiming support for a future PHP 9
Quality
Test coverage is at 98%, PHPStan runs at level 10 and the security scan runs the project's own Psalm. The suite supports PHPUnit 10.5, 12 and 13.
Full Changelog: v2.0.0...v2.1.0
v1.5.1
Fixed
-
gesdinet:jwt:clearcrashed witharray_map(): Argument #2 ($array) must be of type array, Doctrine\ODM\MongoDB\Iterator\CachingIterator givenwhen using the MongoDB ODM.The ORM repository returns an array, but the ODM one returns a
CachingIterator, andRefreshTokenManager::revokeAllInvalid()passed it straight through to the command. It now always returns theRefreshTokenInterface[]documented byRefreshTokenManagerInterface, whatever the repository returns.
Reported in #424 by @melkamar.
Full Changelog: v1.5.0...v1.5.1
v2.0.0
What's Changed
- [1.x] Add forward compat layer for changed logout listener configuration by @mbabker in #350
- 2.0 Proposal by @mbabker in #347
- Use modern filesystem layout by @mbabker in #401
- Use PHPUnit 10 only by @mbabker in #400
- Adjust setup for the ORMTestCase to avoid some deprecations with ORM 3.4 by @mbabker in #399
- Improve the batch cleanup implementation by @mbabker in #403
- feat: implement delete with return number deletions. Issue #404 by @shakaran in #405
- Add support for Symfony 8 by @Kyzegs in #415
- fix: request->get is gone, bc fallback by @endroid in #417
- build(deps-dev): update rector/jack requirement from ^0.2.5 to ^0.5.0 by @dependabot[bot] in #420
- feat: bump rector version 2.2 from 2.1 by @shakaran in #421
New Contributors
- @Kyzegs made their first contribution in #415
- @dependabot[bot] made their first contribution in #420
Full Changelog: v1.5.0...v2.0.0
v2.0.0-beta
What's Changed
- [1.x] Add forward compat layer for changed logout listener configuration by @mbabker in #350
- 2.0 Proposal by @mbabker in #347
- Use modern filesystem layout by @mbabker in #401
- Use PHPUnit 10 only by @mbabker in #400
- Adjust setup for the ORMTestCase to avoid some deprecations with ORM 3.4 by @mbabker in #399
- Improve the batch cleanup implementation by @mbabker in #403
- feat: implement delete with return number deletions. Issue #404 by @shakaran in #405
- Add support for Symfony 8 by @Kyzegs in #415
- fix: request->get is gone, bc fallback by @endroid in #417
- build(deps-dev): update rector/jack requirement from ^0.2.5 to ^0.5.0 by @dependabot[bot] in #420
- feat: bump rector version 2.2 from 2.1 by @shakaran in #421
New Contributors
Full Changelog: v1.5.0...v2.0.0-beta
This is a pre-release as non-production ready for testing. Bugs or testing is welcome