ipalEnvRules: PAYLOAD_SECRET at least 32 characters in production

New option secretMinLength (default 32, 0 turns it off); checked only with
NODE_ENV=production. Docs: env table, deployment (what changing the secret
does, checked in Payload 3.94.1 and payload-2fa), AGENT.md, ipal-reference,
ipal-setup. Tests: short secret fails in production, passes in dev, 0 and a
custom minimum.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-24 00:01:18 +01:00
co-authored by Claude Opus 5.5
parent 40fed78da2
commit 36f8f69f82
13 changed files with 68 additions and 12 deletions
+15 -1
View File
@@ -26,6 +26,11 @@ export type IpalEnvFeatures = {
* the client IP (see clientIp). Outside production it stays optional.
*/
ipHeader?: boolean
/**
* Minimum length of PAYLOAD_SECRET, checked in production only (NODE_ENV=production). Payload signs
* login tokens and encrypts API keys with it, so a short secret is weak. Default 32; 0 turns it off.
*/
secretMinLength?: number
/** Override the Payload secret var. Default 'PAYLOAD_SECRET'. */
secretVar?: string
/** Override the site-URL var. Default 'NEXT_PUBLIC_SERVER_URL'. */
@@ -75,6 +80,7 @@ export function ipalEnvRules(features: IpalEnvFeatures = {}): EnvRule[] {
databaseVar = 'DATABASE_URI',
emailGraph = false,
ipHeader = false,
secretMinLength = 32,
secretVar = 'PAYLOAD_SECRET',
serverUrlVar = 'NEXT_PUBLIC_SERVER_URL',
storage = false,
@@ -83,7 +89,15 @@ export function ipalEnvRules(features: IpalEnvFeatures = {}): EnvRule[] {
const rules: EnvRule[] = [
{ name: databaseVar, description: 'Database connection string (e.g. MongoDB URI)' },
{ name: secretVar, description: 'Payload secret used to sign tokens' },
{
name: secretVar,
description: 'Payload secret used to sign tokens',
...(secretMinLength > 0 && process.env.NODE_ENV === 'production' && {
validate: (value: string) =>
value.length >= secretMinLength ||
`${secretVar} must be at least ${secretMinLength} characters in production (got ${value.length}) — use a long random value, or ipalEnvRules({ secretMinLength }) to change the minimum (0 turns the check off)`,
}),
},
{ name: serverUrlVar, description: 'Public site origin, e.g. https://example.com', kind: 'url' },
{
name: 'NODE_ENV',