{"record":{"id":"4b2a65e8cf1c3d74","repo":"Tencent/WeKnora","slug":"weknora-redis-namespace-must-not-contain-control-c","errorCode":null,"errorMessage":"WEKNORA_REDIS_NAMESPACE must not contain control characters","messagePattern":"WEKNORA_REDIS_NAMESPACE must not contain control characters","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sandbox/session_binding_redis.go","lineNumber":409,"sourceCode":"\treturn \"weknora:sandbox:session:{\" + s.hashTag(key) + \"}:create-lock\"\n}\n\nfunc (s *RedisSessionSandboxBindingStore) hashTag(key SessionSandboxKey) string {\n\treturn fmt.Sprintf(\"%s:%d:%s\", s.namespace, key.TenantID, key.SessionID)\n}\n\nvar (\n\t_ tenantBindingScanner  = (*RedisSessionSandboxBindingStore)(nil)\n\t_ sessionTurnLeaseStore = (*RedisSessionSandboxBindingStore)(nil)\n)\n\nfunc validateRedisNamespace(namespace string) error {\n\tif strings.ContainsAny(namespace, \"{}\") {\n\t\treturn errors.New(\"WEKNORA_REDIS_NAMESPACE must not contain braces\")\n\t}\n\tfor _, r := range namespace {\n\t\tif unicode.IsControl(r) {\n\t\t\treturn errors.New(\"WEKNORA_REDIS_NAMESPACE must not contain control characters\")\n\t\t}\n\t}\n\treturn nil\n}\n","sourceCodeStart":391,"sourceCodeEnd":414,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/sandbox/session_binding_redis.go#L391-L414","documentation":"validateRedisNamespace rejects a WEKNORA_REDIS_NAMESPACE containing Unicode control characters. Control chars produce malformed or ambiguous Redis keys and log output, so NewRedisSessionSandboxBindingStore rejects them at startup.","triggerScenarios":"Starting the service with WEKNORA_REDIS_NAMESPACE containing control runes (e.g. trailing \\n from an untrimmed env file, \\r from Windows CRLF, or an embedded \\t).","commonSituations":"Docker/K8s secret mounted with a trailing newline loaded verbatim into the env var; .env file edited on Windows; echo/base64 mishandling adding a newline.","solutions":["Trim the env value when loading (strings.TrimSpace) or fix at the loader/secret-mount layer.","Fix the .env/secret source so the value has no trailing newline (printf without \\n).","Verify bytes with `echo -n \"$WEKNORA_REDIS_NAMESPACE\" | od -c` and remove \\n/\\r."],"exampleFix":"// before\nns := os.Getenv(\"WEKNORA_REDIS_NAMESPACE\") // \"weknora\\n\"\nstore, err := sandbox.NewRedisSessionSandboxBindingStore(client, ns) // fails\n// after\nns := strings.TrimSpace(os.Getenv(\"WEKNORA_REDIS_NAMESPACE\"))\nstore, err := sandbox.NewRedisSessionSandboxBindingStore(client, ns)","handlingStrategy":"validation","validationCode":"ns := strings.TrimSpace(os.Getenv(\"WEKNORA_REDIS_NAMESPACE\"))\nfor _, r := range ns {\n    if unicode.IsControl(r) { return fmt.Errorf(\"WEKNORA_REDIS_NAMESPACE has control chars: %q\", ns) }\n}","typeGuard":null,"tryCatchPattern":"store, err := sandbox.NewRedisSessionSandboxBindingStore(client, ns)\nif err != nil {\n    return fmt.Errorf(\"redis namespace %q rejected: %w\", ns, err)\n}","preventionTips":["Trim all env values loaded from files/secrets.","Avoid Windows CRLF .env files or normalize them on load.","Verify env bytes with od -c when startup validation fails."],"tags":["go","sandbox","redis","configuration","env-var"],"backgroundTag":"invalid-env-var","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}