{"record":{"id":"1f2ffc50a5da89d8","repo":"JuliusBrussee/caveman","slug":"production-refuses-default-or-empty-s","errorCode":null,"errorMessage":"production refuses default or empty %s","messagePattern":"production refuses default or empty (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"shared/platform/env/env.go","lineNumber":101,"sourceCode":"\tif !IsProduction() {\n\t\treturn nil\n\t}\n\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","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/env/env.go#L83-L119","documentation":"validateProductionTextSecrets rejects a text secret env var that is empty, whitespace-only, exactly 'generated', or contains 'changeme' (case-insensitive), erroring with 'production refuses default or empty %s'. The library enforces that production secrets are explicitly supplied, operator-chosen values rather than scaffolding defaults.","triggerScenarios":"Calling RefuseProductionDefaults or RefuseGatewayProductionDefaults while one of CAVE_JWT_SIGNING_KEY / CAVE_BOOTSTRAP_TOKEN (or other listed names) is unset, blank, 'generated', or contains 'changeme'.","commonSituations":"Fresh deployment where the secret env var was never set; a bootstrap script leaving 'generated' placeholder; docs/tutorial values like 'changeme-super-secret' copied into prod.","solutions":["Set the named env var to a strong, unique secret (>=32 chars, >=8 distinct bytes).","Remove any 'changeme' substring or 'generated' placeholder from the value.","Generate with e.g. `openssl rand -base64 48` and inject via your secret manager.","If this is not production, switch to local mode where defaults are permitted."],"exampleFix":"// before\ndocker run -e CAVE_ENV=production -e CAVE_JWT_SIGNING_KEY=changeme-jwt-key cave\n// error: production refuses default or empty CAVE_JWT_SIGNING_KEY\n\n// after\ndocker run -e CAVE_ENV=production \\\n  -e CAVE_JWT_SIGNING_KEY=\"$(openssl rand -base64 48)\" \\\n  -e CAVE_BOOTSTRAP_TOKEN=\"$(openssl rand -base64 48)\" cave","handlingStrategy":"validation","validationCode":"func checkSecret(name string) error {\n    v := strings.TrimSpace(os.Getenv(name))\n    if v == \"\" || v == \"generated\" || strings.Contains(strings.ToLower(v), \"changeme\") {\n        return fmt.Errorf(\"%s must be set to a strong secret\", name)\n    }\n    return nil\n}\n// run for each of CAVE_JWT_SIGNING_KEY, CAVE_BOOTSTRAP_TOKEN before RefuseProductionDefaults","typeGuard":null,"tryCatchPattern":"if err := env.RefuseProductionDefaults(); err != nil {\n    if strings.Contains(err.Error(), \"refuses default or empty\") {\n        log.Fatalf(\"unset/placeholder secret: %v\", err)\n    }\n    return err\n}","preventionTips":["Generate secrets with a CSPRNG (`openssl rand -base64 48`); never hand-type them.","Ban placeholder words like 'changeme'/'generated' via deploy-time linting of env files.","Inject secrets from a secret manager; never commit or template default values."],"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"}