Skip to content

Validate JWT signing keys at startup and document key rotation #46

Description

@priscaenoch

Problem

src/auth/keys.ts loads an RS256 key pair from JWT_PRIVATE_KEY/JWT_PUBLIC_KEY (with JWT_KEY_ID) and src/auth/tokens.ts signs tokens with it. If those environment variables are absent or malformed, the failure surfaces later at token-signing/verification time rather than at boot, and it is not documented how to generate the keys, what JWT_KEY_ID is for, or how to rotate keys. A silent or insecure fallback in production would be a serious auth problem.

What needs to be done

  • Validate at startup that the required JWT keys are present and parse as a valid RS256 key pair; fail fast with a clear message when they are missing or invalid in a production configuration.
  • Ensure there is no insecure default/fallback key path in production.
  • Document how to generate the key pair, the role of JWT_KEY_ID, and a rotation procedure (supporting multiple valid kids during rotation).
  • Confirm keys are never logged.

Files

  • src/auth/keys.ts, src/auth/tokens.ts
  • .env.example, README.md

Acceptance deliverables

  • Missing/invalid JWT keys fail at startup with an actionable message.
  • Key generation and rotation are documented.
  • All CI checks pass; the change cannot be merged until CI is green.

Tests to pass

  • Test: startup validation rejects missing/malformed keys.
  • Test: a token signed with the configured key verifies against the configured public key.

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardThird CampaignCampaign: Third CampaignenhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions