Feature: auto-generate the paid-posts encryption key (no env needed)
Nobody should have to hand-edit the env to use paid posts. CryptoBox now
resolves its key as: PAID_SECRET (env) if set, else a persisted key file
next to the database, auto-generated (0600) on first use. New installs and
existing users after an update get a key with zero config; a self-hoster
who set PAID_SECRET (Bart already did) keeps working unchanged, env wins.
The key lives OUTSIDE the sqlite DB on purpose: encrypting the Patreon
secrets is pointless if the key sits in the same file a DB dump would leak.
If the file can't be persisted (read-only fs) the box stays "not ready"
rather than using an ephemeral key that a restart would lose, so ciphertext
never becomes undecryptable.
Admin copy that referenced PAID_SECRET is updated: the warning now describes
the real remaining failure (key can't be created/read), not a missing env.
Changed files:
src/services/CryptoBox.js
- resolve secret: env, else auto-generated 0600 key file by the database
src/services/PaidPatreonService.js
- save error no longer names PAID_SECRET
src/routes/admin-paid.js, src/views/pages/admin-paid.ejs
- not-ready copy describes the key file, not a missing env var
New file:
test/paid-secret.test.js
- without PAID_SECRET: key file generated (0600), encrypt/decrypt
roundtrips, key persists
remarks: the generated storage/.paid-secret must be backed up alongside the
DB, or the stored Patreon secrets can't be decrypted after a restore.
-robo
Co-Authored-By: Claude Opus 4.8 <noreply@…>