fix: require dedicated secrets for download signing and API key encryption#74
fix: require dedicated secrets for download signing and API key encryption#74bmersereau wants to merge 4 commits into
Conversation
…ption (willchen96#66) Remove SUPABASE_SECRET_KEY fallbacks from downloadTokens.getSecret() and userApiKeys.encryptionKey(). Each subsystem now requires its own explicitly configured secret. Add assertSecretIsolation() called at startup to enforce both presence and uniqueness of the three secrets at boot time.
PR Review: fix: require dedicated secrets for download signing and API key encryptionSummaryThis PR eliminates the Risk Assessment
Review by CategoryCorrectness
Security
Test Coverage
Test Coverage Assessment
Questions
Verdict
What I Verified
|
PR Review (follow-up): fix: require dedicated secrets for download signing and API key encryptionAll issues from the previous review have been addressed. This is a clean pass. What changed since last review
Remaining (non-blocking)
Verdict
What I Verified
|
Summary
SUPABASE_SECRET_KEYfallback fromdownloadTokens.getSecret()—DOWNLOAD_SIGNING_SECRETis now requireduserApiKeys.encryptionKey()—USER_API_KEYS_ENCRYPTION_SECRETis now requiredassertSecretIsolation()called at server startup to enforce presence, uniqueness, and cross-secret isolation of each secretdownloadTokens.tsto reflect the TTL-based expiration added in PR fix: add expiration to download tokens (30-day TTL) #77Closes #66
Closes #82
Closes #83
Closes #88
Changes
backend/src/lib/downloadTokens.ts—getSecret()reads onlyDOWNLOAD_SIGNING_SECRET; JSDoc updated to reference configurable TTLbackend/src/lib/userApiKeys.ts—encryptionKey()reads onlyUSER_API_KEYS_ENCRYPTION_SECRETbackend/src/lib/startup.ts— newassertSecretIsolation()validates at boot: missing vars throw, secrets matchingSUPABASE_SECRET_KEYthrow, andDOWNLOAD_SIGNING_SECRET === USER_API_KEYS_ENCRYPTION_SECRETthrowsbackend/src/index.ts— callassertSecretIsolation()before the server startsbackend/vitest.config.ts— vitest config excludingdist/backend/src/lib/__tests__/secretIsolation.test.ts— 11 vitest unit tests covering all pathsTest plan
npm testpasses (11/11) inbackend/npm run buildpasses with no TypeScript errors.envmust be updated before restarting backend (see migration note below)Before restarting the backend after this change, ensure your environment has:
Generate fresh values with
openssl rand -hex 32.If you previously had
API_KEYS_ENCRYPTION_SECRETset (an undocumented legacy fallback that was removed in this PR): setUSER_API_KEYS_ENCRYPTION_SECRETto that same value. Do not generate a new value — doing so will change the AES key and make all stored user API keys in the database unreadable.