{"record":{"id":"8b4edb9b823ac1a5","repo":"JuliusBrussee/caveman","slug":"production-requires-s-to-contain-at-least-32-char","errorCode":null,"errorMessage":"production requires %s to contain at least 32 characters","messagePattern":"production requires (.+?) to contain at least 32 characters","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/env/env.go","lineNumber":104,"sourceCode":"\tif err := validateProductionTextSecrets([]string{\"CAVE_KEY_HASH_PEPPER\"}); err != nil {\n\t\treturn err\n\t}\n\tif Bool(\"CAVE_REPLAY_ENABLED\", false) {\n\t\tif err := validateProductionTextSecrets([]string{\"CAVE_ROUTER_REPLAY_TOKEN\"}); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\treturn validateProductionPublicURL()\n}\n\nfunc validateProductionTextSecrets(names []string) error {\n\tfor _, name := range names {\n\t\tv := strings.TrimSpace(os.Getenv(name))\n\t\tif v == \"\" || v == \"generated\" || strings.Contains(strings.ToLower(v), \"changeme\") {\n\t\t\treturn fmt.Errorf(\"production refuses default or empty %s\", name)\n\t\t}\n\t\tif len(v) < 32 {\n\t\t\treturn fmt.Errorf(\"production requires %s to contain at least 32 characters\", name)\n\t\t}\n\t\tif distinctBytes([]byte(v)) < 8 {\n\t\t\treturn fmt.Errorf(\"production refuses low-diversity %s\", name)\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc validateProductionPublicURL() error {\n\tpublicURL := strings.TrimSpace(os.Getenv(\"CAVE_PUBLIC_URL\"))\n\tu, err := url.Parse(publicURL)\n\tif err != nil || u.Scheme != \"https\" || u.Hostname() == \"\" || u.User != nil || u.RawQuery != \"\" || u.Fragment != \"\" || (u.Path != \"\" && u.Path != \"/\") {\n\t\treturn fmt.Errorf(\"production requires CAVE_PUBLIC_URL to be an HTTPS origin without credentials, path, query, or fragment\")\n\t}\n\treturn nil\n}\n\nfunc distinctBytes(value []byte) int {","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/env/env.go#L86-L122","documentation":"validateProductionTextSecrets requires each production text secret to be at least 32 bytes long after trimming; shorter values get 'production requires %s to contain at least 32 characters'. It enforces a minimum entropy floor so production secrets cannot be brute-forced.","triggerScenarios":"RefuseProductionDefaults / RefuseGatewayProductionDefaults runs while CAVE_JWT_SIGNING_KEY or CAVE_BOOTSTRAP_TOKEN is set to a non-empty, non-default string shorter than 32 characters.","commonSituations":"Hand-typed secrets like 'my-dev-key-123'; keys truncated by a secrets-manager template; older deployments with short secrets hitting the new validation after upgrade.","solutions":["Replace the secret with a value of at least 32 characters (e.g. `openssl rand -base64 48`).","Check for trimming/truncation in your deployment tooling — the check runs on strings.TrimSpace(os.Getenv(name)).","Rotate dependent systems (tokens signed with the old key) after rotating the secret.","If this is not production, use local mode which does not enforce the length floor."],"exampleFix":"// before\nexport CAVE_JWT_SIGNING_KEY=\"short-key\"\n// error: production requires CAVE_JWT_SIGNING_KEY to contain at least 32 characters\n\n// after\nexport CAVE_JWT_SIGNING_KEY=\"$(openssl rand -base64 48)\"  # 64 chars","handlingStrategy":"validation","validationCode":"func checkSecretLength(name string) error {\n    if len(strings.TrimSpace(os.Getenv(name))) < 32 {\n        return fmt.Errorf(\"%s must be at least 32 characters\", name)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := env.RefuseProductionDefaults(); err != nil {\n    if strings.Contains(err.Error(), \"at least 32 characters\") {\n        log.Fatalf(\"secret too short: %v\", err)\n    }\n    return err\n}","preventionTips":["Standardize on >=32-char CSPRNG-generated secrets in your provisioning scripts.","Watch for truncation in deployment templating (some tools cut long values).","Plan rotation: lengthening a signing key invalidates previously issued tokens."],"tags":["secrets","production","env-var","validation"],"backgroundTag":"invalid-env-var-value","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}