Skip to content

Commit 0c75c56

Browse files
fix: normalize default SOURCEBOT_ENCRYPTION_KEY to 32 characters
The default SOURCEBOT_ENCRYPTION_KEY in docker-compose is 33 zeros, which fails the 32-character (AES-256) length validation. Preprocess the value so the all-zeros default is trimmed to 32 characters before validation. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 8c37902 commit 0c75c56

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

packages/shared/src/env.server.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,18 @@ const options = {
341341
// The key is read as ASCII (1 char = 1 byte), so AES-256's 32-byte key
342342
// requirement means this must be exactly 32 characters. Generate one with
343343
// `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-
}),
344+
SOURCEBOT_ENCRYPTION_KEY: z.preprocess(
345+
// @hack in our docker-compose.yml, we mistakenly used a
346+
// encryption key with _33_ zeros. As a hacky mechanism to
347+
// fix peoples deployments without requiring them to update
348+
// their encryption key, we look for keys with this pattern
349+
// and coerce them into _32_ zeros.
350+
// @see https://github.com/sourcebot-dev/sourcebot/commit/e30e75e7af96308b3b063bb3aed8369f5b15aa2e
351+
(value) => value === "0".repeat(33) ? "0".repeat(32) : value,
352+
z.string().length(32, {
353+
message: "SOURCEBOT_ENCRYPTION_KEY must be exactly 32 characters (a 256-bit AES key). Generate one with `openssl rand -base64 24`.",
354+
}),
355+
),
347356
SOURCEBOT_INSTALL_ID: z.string().default("unknown"),
348357
SOURCEBOT_LIGHTHOUSE_URL: z.string().url().default("https://deployments.sourcebot.dev"),
349358

0 commit comments

Comments
 (0)