Skip to content

fix: store link tokens encrypted in job arguments - #299

Open
jaspermayone wants to merge 1 commit into
mainfrom
fix-encrypt-token-job-arguments
Open

jaspermayone wants to merge 1 commit into
mainfrom
fix-encrypt-token-job-arguments

Conversation

@jaspermayone

Copy link
Copy Markdown
Member

Follow-up to GHSA-3rx4-8wxp-j549 and #298.

Problem

MagicLinkJob and the mail jobs of GuardianConsentMailer carried the raw link token as a plain-text job argument. The queue table and /admin/jobs thus held a usable link. #298 deletes finished rows after one day, but a failed job is not finished, so its row kept the token with no time limit.

Change

  • LinkToken (lib/link_token.rb) wraps a raw link token. Its Active Job serializer stores the token encrypted (AES-256-GCM, key derived from secret_key_base).
  • The three places that enqueue a token wrap it: User#send_magic_link, and the request and receipt mails in GuardianConsentFlow.
  • MagicLinkJob and TokenMailDeliveryJob refuse a plain String token at enqueue, so a new caller that does not wrap the token fails at once.
  • The mailers do not change. A URL helper reads the token through to_param.

A failed token job can now stay in /admin/jobs for a retry, because its row holds no usable token.

flowchart LR
  A[Caller wraps token in LinkToken] --> B[Active Job serializes: encrypted value]
  B --> C[(solid_queue_jobs.arguments)]
  C --> D[Worker deserializes: LinkToken]
  D --> E[Mailer builds the link with to_param]
Loading

Deploy notes

  • A job that is in the queue with a plain token at deploy time still runs.
  • After a rollback to the previous image, the old code cannot read a queued job that holds an encrypted token. The job fails. Deploy the new image again, then retry the failed jobs in /admin/jobs.
  • After a rotation of secret_key_base, a token job that is still in the queue fails.
  • Rows written before the deploy keep the plain token. Finished rows go after one day (fix: delete finished job rows after one day #298). An old failed token job stays until a person retries or discards it.

Checks

  • bundle exec rspec: 2955 examples, 0 failures.
  • bin/rubocop: no offenses. bin/brakeman: 0 warnings. bin/rails zeitwerk:check: passed.
  • The new specs fail when the token is not wrapped at a call site (tested by hand).
  • The specs check what Active Job serializes, which is what Solid Queue stores. They do not write a real queue row.

@jaspermayone
jaspermayone requested a review from a team November 18, 2026 17:01
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.

1 participant