Skip to content

Commit df4b613

Browse files
fix(shared): validate SOURCEBOT_ENCRYPTION_KEY is 32 chars
The key is used directly as a 32-byte AES-256-CBC key. Validate its length at startup so a misconfigured key fails fast with an actionable message instead of a RangeError deep in an encryption call. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent a84e7a9 commit df4b613

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

packages/shared/src/env.server.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,13 @@ const options = {
337337
PERMISSION_SYNC_REPO_DRIVEN_ENABLED: booleanSchema.default('true'),
338338
EXPERIMENT_ASK_GH_ENABLED: booleanSchema.default('false'),
339339

340-
SOURCEBOT_ENCRYPTION_KEY: z.string(),
340+
// Used as the key for AES-256-CBC encryption (@see shared/src/crypto.ts).
341+
// The key is read as ASCII (1 char = 1 byte), so AES-256's 32-byte key
342+
// requirement means this must be exactly 32 characters. Generate one with
343+
// `openssl rand -base64 24` (24 random bytes => a 32-character base64 string).
344+
SOURCEBOT_ENCRYPTION_KEY: z.string().length(32, {
345+
message: "SOURCEBOT_ENCRYPTION_KEY must be exactly 32 characters (a 256-bit AES key). Generate one with `openssl rand -base64 24`.",
346+
}),
341347
SOURCEBOT_INSTALL_ID: z.string().default("unknown"),
342348
SOURCEBOT_LIGHTHOUSE_URL: z.string().url().default("https://deployments.sourcebot.dev"),
343349

0 commit comments

Comments
 (0)