{"record":{"id":"0c79a5818b6bebee","repo":"ruvnet/ruflo","slug":"namespace-contains-disallowed-characters","errorCode":null,"errorMessage":"Namespace contains disallowed characters","messagePattern":"Namespace contains disallowed characters","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"v3/@claude-flow/cli/src/mcp-tools/memory-tools.ts","lineNumber":86,"sourceCode":"const DANGEROUS_KEY_CHARS = /[;&|`$(){}[\\]<>!#\\\\\\0]|\\.\\.[/\\\\]/g;\nconst DANGEROUS_KEY_PATTERN = /[;&|`$(){}[\\]<>!#\\\\\\0]|\\.\\.[/\\\\]/;\n\nfunction validateMemoryInput(key?: string, value?: string, query?: string, namespace?: string): void {\n  if (key && key.length > MAX_KEY_LENGTH) {\n    throw new Error(`Key exceeds maximum length of ${MAX_KEY_LENGTH} characters`);\n  }\n  if (value && value.length > MAX_VALUE_SIZE) {\n    throw new Error(`Value exceeds maximum size of ${MAX_VALUE_SIZE} bytes`);\n  }\n  if (query && query.length > MAX_QUERY_LENGTH) {\n    throw new Error(`Query exceeds maximum length of ${MAX_QUERY_LENGTH} characters`);\n  }\n  // Reject path traversal and shell metacharacters in keys/namespaces (#1425)\n  if (key && DANGEROUS_KEY_PATTERN.test(key)) {\n    throw new Error('Key contains disallowed characters');\n  }\n  if (namespace && DANGEROUS_KEY_PATTERN.test(namespace)) {\n    throw new Error('Namespace contains disallowed characters');\n  }\n}\n\n// #1884 — sanitize a key produced from arbitrary input (markdown headings,\n// frontmatter names, file names) so it survives validateMemoryInput on the\n// read/delete path. Replaces every dangerous char with `_`. Truncates to\n// MAX_KEY_LENGTH so the bound check in validateMemoryInput also passes.\n// Keep this in sync with DANGEROUS_KEY_PATTERN — they share DANGEROUS_KEY_CHARS.\nfunction sanitizeMemoryKey(key: string): string {\n  const safe = key.replace(DANGEROUS_KEY_CHARS, '_');\n  return safe.length > MAX_KEY_LENGTH ? safe.slice(0, MAX_KEY_LENGTH) : safe;\n}\n\n// #1937 — minimal glob → RegExp helper for memory_import_claude exclusion\n// patterns. Anchored. Supports the three operators the issue's voice-fidelity\n// workflow needs:\n//   `**` — any chars including path separators\n//   `*`  — any chars except path separators","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/ruvnet/ruflo/blob/6b01dc5a687b26b3e218f796de45ec51f8fa9e8c/v3/@claude-flow/cli/src/mcp-tools/memory-tools.ts#L68-L104","documentation":"Thrown by validateMemoryInput when a namespace matches the same DANGEROUS_KEY_PATTERN as keys. Namespaces partition the memory store into directories/collections and feed filesystem paths, so shell metacharacters and path-traversal sequences are rejected identically to keys. The check is symmetric with the key check (the #1884 symmetry fix).","triggerScenarios":"Calling any memory tool with a --namespace containing ';', '|', '$', backticks, '../', brackets, or null bytes. The regex test runs after the namespace length is implicitly acceptable (no separate namespace length cap shown).","commonSituations":"User/tenant IDs used as namespaces that contain slashes or special chars; LLM-generated namespace strings; path-traversal attempts targeting another namespace's data; namespaces built from file paths.","solutions":["Restrict namespaces to an allowlist charset ([A-Za-z0-9._-]).","Hash or slugify arbitrary namespace input before calling memory tools.","Validate namespaces with the same scrubbing used for keys.","Never pass raw user input as a namespace."],"exampleFix":"// before\nmemory store --namespace \"tenant/a;b\" --key k --value v\n// after\nconst ns = tenantId.replace(/[^A-Za-z0-9._-]/g, '_')\nmemory store --namespace \"$ns\" --key k --value v","handlingStrategy":"validation","validationCode":"function sanitizeNamespace(ns) {\n  return ns.replace(/[;&|`$(){}[\\]<>!#\\\\\\0]|\\.\\.[\\/\\\\]/g, '_');\n}","typeGuard":"function isSafeNamespace(ns: string): boolean {\n  return !/[;&|`$(){}[\\]<>!#\\\\\\0]|\\.\\.[\\/\\\\]/.test(ns);\n}","tryCatchPattern":null,"preventionTips":["Slugify tenant/user IDs before using them as namespaces.","Allowlist namespace charset at the application boundary.","Apply the same scrubbing used for keys."],"tags":["memory","security","injection","path-traversal","validation","input-validation"],"backgroundTag":null,"analyzedSha":"6b01dc5a687b26b3e218f796de45ec51f8fa9e8c","analyzedAt":"2026-08-12T13:20:50.148Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}