{"record":{"id":"04726b9d9e260c48","repo":"JuliusBrussee/caveman","slug":"production-refuses-low-diversity-s","errorCode":null,"errorMessage":"production refuses low-diversity %s","messagePattern":"production refuses low-diversity (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/env/env.go","lineNumber":107,"sourceCode":"\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 {\n\tseen := map[byte]struct{}{}\n\tfor _, b := range value {\n\t\tseen[b] = struct{}{}","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/env/env.go#L89-L125","documentation":"validateProductionTextSecrets counts distinct bytes in the secret and rejects values with fewer than 8 unique bytes ('production refuses low-diversity %s'). A long but repetitive string (e.g. 'aaaa...' or repeated words) passes the length check but has effectively low entropy, so the library refuses it.","triggerScenarios":"RefuseProductionDefaults / RefuseGatewayProductionDefaults sees a secret >=32 chars whose byte content has <8 distinct byte values — e.g. a repeated single character or pattern.","commonSituations":"Secrets padded with '0000...' or 'xxxx' to satisfy length checks; programmatically generated filler strings; misconfigured templating that repeats one character.","solutions":["Replace the secret with high-entropy random data (`openssl rand -base64 48` or equivalent).","Avoid padding tricks — use genuinely random bytes rather than repeating characters.","Verify with a quick check that the value has at least 8 distinct bytes.","If this is not production, switch to local mode which skips the diversity check."],"exampleFix":"// before\nexport CAVE_BOOTSTRAP_TOKEN=\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\" // 1 distinct byte\n// error: production refuses low-diversity CAVE_BOOTSTRAP_TOKEN\n\n// after\nexport CAVE_BOOTSTRAP_TOKEN=\"$(openssl rand -base64 48)\"","handlingStrategy":"validation","validationCode":"func distinctBytes(b []byte) int {\n    seen := map[byte]struct{}{}\n    for _, c := range b { seen[c] = struct{}{} }\n    return len(seen)\n}\nfunc checkSecretDiversity(name string) error {\n    if distinctBytes([]byte(strings.TrimSpace(os.Getenv(name)))) < 8 {\n        return fmt.Errorf(\"%s has too little entropy; use random data\", name)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := env.RefuseProductionDefaults(); err != nil {\n    if strings.Contains(err.Error(), \"low-diversity\") {\n        log.Fatalf(\"regenerate secret with random bytes: %v\", err)\n    }\n    return err\n}","preventionTips":["Never pad secrets with repeated characters to meet length rules.","Always generate secrets from a CSPRNG; avoid human-chosen or patterned values.","Add a pre-deploy entropy check (distinct bytes >= 8) to your config validation suite."],"tags":["secrets","entropy","production","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"}