Repository navigation
Open
Description
Problem
JWT_SECRET is used for five unrelated purposes: signing session tokens, signing unsubscribe and click-tracking links, encrypting stored SMTP credentials, encrypting stored IMAP credentials, and encrypting the license key. One secret, no versioning.
The practical consequence is that the secret cannot be rotated. Rotating it logs every user out (acceptable) and makes every stored SMTP and IMAP credential undecryptable (not acceptable — every project stops sending until someone re-enters credentials by hand). A leaked or merely old secret therefore stays in place, which is the opposite of what a secret-hygiene story needs.
Proposal
Separate signing from encryption and make encryption keys rotatable:
- Introduce
ENCRYPTION_KEYfor data at rest (SMTP, IMAP, license key).JWT_SECRETkeeps signing sessions and links only. On upgrade, a missingENCRYPTION_KEYfalls back toJWT_SECRETso nothing breaks, with a startup WARN recommending the split. - Version the key:
ENCRYPTION_KEYSaccepts a comma-separated list, newest first. Ciphertext carries the key version; decryption tries the matching version; encryption always uses the newest. - Lazy re-encryption: whenever a credential is read with an older key version, rewrite it with the newest. An optional
senddock-cli secrets rotate(see senddock-cli — admin and ops CLI bundled in the Docker image #76) re-encrypts everything eagerly. JWT_SECRETrotation path: document that it invalidates sessions and signed links, and support a short dual-key grace window for link verification so in-flight unsubscribe and tracking links keep working after rotation.- Startup check: refuse to boot if
ENCRYPTION_KEYSis set but cannot decrypt a sample row, to fail loudly on misconfiguration instead of silently disabling sending.
Acceptance
-
ENCRYPTION_KEY/ENCRYPTION_KEYSread by config, withJWT_SECRETfallback and startup warning - Versioned ciphertext format for SMTP, IMAP and license key, with migration of existing rows to version 1 on first read
- Lazy re-encryption on read; unit tests for encrypt/decrypt across versions and for rotation
- Grace window for link signature verification during
JWT_SECRETrotation - Docs: configuration reference for the new variables and a "Rotating secrets" runbook under self-hosting
Activity