packagist gesdinet/jwt-refresh-token-bundle v3.2.0

50 minutes ago

Upgrade if you use single_use: true or Doctrine DBAL 4.6. This release closes a concurrency race on single-use refresh token rotation, migrates all Doctrine date mappings to immutable types (datetime_immutable and date_immutable), and adds six opt-in operational and developer-experience features.

Security & Concurrency: refusing concurrent single_use refreshes

With single_use: true, two refresh requests presenting the same token at the same time could both be given a new pair, which is the stolen-token case rotation exists to end. The success listener ignored what delete() reported, and with hash_tokens it looked the token up a second time, so a request whose token had just been spent by the other was handed a replacement in a chain of its own, out of reach of reuse detection and max_session_lifetime.

The token is now spent only when the storage reports deleting its row; the losing request is refused with TokenNotFoundException like a replayed token, with nothing issued. PostRefreshTokenAuthenticationToken::getPresentedRefreshToken() carries the presented value for the request (not serialized), and Doctrine\RefreshTokenManager::delete() now asks the database what it deleted when the repository does not implement DeleteRefreshTokenRepositoryInterface.

Contributed by Karel Sommer (@calvera) in #437.

Doctrine DBAL 4.6 compatibility (datetime_immutable and date_immutable)

Doctrine DBAL 4.6 deprecated mutable datetime types in favour of datetime_immutable.

  • config/doctrine/RefreshToken.orm.xml now maps valid and familyValid as datetime_immutable.
  • config/doctrine/RefreshToken.mongodb.xml now maps valid and familyValid as date_immutable.
  • Doctrine\DBAL\TableSchemaManager and Doctrine\DBAL\RefreshTokenManager default valid and familyValid to Types::DATETIME_IMMUTABLE while respecting custom dbal_columns overrides and normalizing any DateTimeInterface input to match the configured type.
  • Models, repositories, listeners, commands, and cache hydration now build DateTimeImmutable instances.

No database migration is needed on DBAL 4. Public getters and setters keep ?DateTimeInterface; see UPGRADE-3.2.md if your application checks instanceof \DateTime or calls ->modify() expecting in-place mutation. Fixes #438 and #439.

Added

  • Automatic periodic cleanup via Symfony Scheduler: enable gesdinet_jwt_refresh_token.cleanup_schedule (requires symfony/scheduler) to schedule ClearExpiredRefreshTokensMessage without a system cron job.
  • Sessions CLI & family revocation: bin/console gesdinet:jwt:sessions <username> (with --end=<family>) and bin/console gesdinet:jwt:revoke --family=<family>.
  • Audit events: Event\RefreshTokenCreatedEvent and Event\RefreshTokenRevokedEvent dispatched on token issuance, single-use rotation, and CLI revocation.
  • Symfony Profiler panel: DataCollector\RefreshTokenDataCollector and Web Debug Toolbar panel registered automatically when kernel.debug is true.
  • OpenAPI rate-limit docs: OpenApi\OpenApiFactory now documents 429 Too Many Requests (with Retry-After) when rate_limiter is enabled and preserves custom POST operations already defined on a check_path.
  • Opt-in session metadata: Model\SessionMetadataAwareRefreshTokenInterface and Model\SessionMetadataTrait to record lastUsedAt, ipAddress, and userAgent on issued tokens and expose them on Session\Session.
  • Diagnostic command: bin/console gesdinet:jwt:doctor to audit check_path, hash_tokens, single_use / reuse_detection, rate_limiter, dbal_auto_create_table, and cookie.secure.

Upgrade & Tooling

  • Added UPGRADE-3.2.md and updated UPGRADE-RECTOR.md with 3.0 -> 3.1 and 3.1 -> 3.2 checklists.
  • Verified against Symfony 8.1 and 8.2, PHP 8.4 and 8.5, 100% test coverage (681 tests, 1813 assertions), PHPStan level 10 (bleedingEdge, strict-rules, type-coverage 100%, cognitive-complexity), and Psalm taint analysis.

Don't miss a new jwt-refresh-token-bundle release

NewReleases is sending notifications on new releases.