Skip to content

Token#detach_payload! keeps a cached attached JWT #748

Closed

Description

@OskarEichler

Summary

JWT::Token#detach_payload! sets the detached flag but does not invalidate an already rendered @jwt, so call order changes the result.

Reproduction

token = JWT::Token.new(payload: { data: 'value' })
token.sign!(algorithm: 'HS256', key: 'secret')
attached = token.jwt
token.detach_payload!
raise if token.jwt == attached

On 3.2.0/current behavior, the final call returns the cached attached token. Clearing @jwt when detaching makes the payload segment empty as requested.

Verification

A source-only candidate passes the focused failing/passing model, the 554-example release suite (12 expected OpenSSL 3 pending), focused RuboCop, gem build and Rails 8.1.3.1 JWT integration. No repository tests or changelog were changed during the audit, so this is issue-first for the contribution policy.

Prepared with AI-assisted source review.

Activity

  1. added a commit that references this issue on Sep 5, 2026
    210671e
  2. added a commit that references this issue on Sep 5, 2026
    41fbf31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions