Skip to content

Commit 2928b61

Browse files
authored
🔒 feat: Enforce minimum length for SESSION_SECRET (#49)
Added a check to ensure that the SESSION_SECRET environment variable is at least 32 characters long, enhancing security for admin session encryption. This prevents the use of weak session secrets in production environments.
1 parent 8ceace7 commit 2928b61

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

‎src/server/session.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type * as t from '@/types';
33

44
const DEV_SECRET = 'dev-only-session-secret-minimum-32-chars!';
55

6+
const MIN_SESSION_SECRET_LENGTH = 32;
67
const REVALIDATION_INTERVAL_MS = 60_000;
78
const DEFAULT_IDLE_TIMEOUT_MS = 30 * 60 * 1000;
89

@@ -27,6 +28,12 @@ if (!sessionSecret) {
2728
throw new Error('SESSION_SECRET environment variable must be set for admin session encryption.');
2829
}
2930

31+
if (sessionSecret.length < MIN_SESSION_SECRET_LENGTH) {
32+
throw new Error(
33+
`SESSION_SECRET must be at least ${MIN_SESSION_SECRET_LENGTH} characters for admin session encryption.`,
34+
);
35+
}
36+
3037
if (!process.env.SESSION_SECRET && process.env.NODE_ENV === 'development') {
3138
console.warn(
3239
'[session] Using hardcoded DEV_SECRET — set SESSION_SECRET for production-like environments',

0 commit comments

Comments
 (0)