chore: sync in-progress work across marketing, admin, API and tests
Snapshot of uncommitted work that had accumulated in the tree alongside the Turnstile changes: - marketing pages, SEO helpers (lib/seo.ts, lib/marketing/) and structured data - admin billing actions and a per-user portfolio view, plus an admin error boundary - rate limiting (lib/rate-limit.ts) applied across the /api/v1 surface - CSP and proxy adjustments, accounting/webhook lib updates - Playwright config and an e2e/unit test suite - next bumped to ^16.3.4 with the lockfile regenerated - generated AGENTS.md / CLAUDE.md Authored by other sessions working in this tree; committed here so the Turnstile work could be pushed without leaving the tree dirty. Typecheck passes. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
8f90347659
commit
1d02598786
+19
-1
@@ -3,9 +3,27 @@ import crypto from "crypto"
|
||||
// AES-256-GCM encryption for secrets at rest (OAuth tokens). The key is derived
|
||||
// from ACCOUNTING_ENCRYPTION_KEY, falling back to BETTER_AUTH_SECRET, via SHA-256
|
||||
// so no additional configuration is required.
|
||||
let warnedAboutFallbackKey = false
|
||||
|
||||
function getKey(): Buffer {
|
||||
const secret = process.env.ACCOUNTING_ENCRYPTION_KEY || process.env.BETTER_AUTH_SECRET
|
||||
const dedicated = process.env.ACCOUNTING_ENCRYPTION_KEY
|
||||
const secret = dedicated || process.env.BETTER_AUTH_SECRET
|
||||
if (!secret) throw new Error("No encryption key configured (BETTER_AUTH_SECRET)")
|
||||
|
||||
// Riding on BETTER_AUTH_SECRET works, but couples two independent rotation
|
||||
// schedules: rotating the auth secret would silently make every stored OAuth
|
||||
// token undecryptable, with no migration path and no error until a user's
|
||||
// next accounting sync fails. Warn once so this is caught before that
|
||||
// happens rather than after.
|
||||
if (!dedicated && !warnedAboutFallbackKey) {
|
||||
warnedAboutFallbackKey = true
|
||||
console.warn(
|
||||
"[crypto] ACCOUNTING_ENCRYPTION_KEY is not set — deriving the at-rest key " +
|
||||
"from BETTER_AUTH_SECRET. Rotating BETTER_AUTH_SECRET will make all " +
|
||||
"stored OAuth tokens undecryptable. Set a dedicated key in production."
|
||||
)
|
||||
}
|
||||
|
||||
return crypto.createHash("sha256").update(secret).digest()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user