{"record":{"id":"119a2fde054b805b","repo":"mem0ai/mem0","slug":"invalid-label-name-only-letters-digits-119a2f","errorCode":null,"errorMessage":"Invalid ${label} '${name}': only letters, digits, and underscores are allowed, must start with a letter or underscore, and be at most 128 characters.","messagePattern":"Invalid (.+?) '(.+?)': only letters, digits, and underscores are allowed, must start with a letter or underscore, and be at most 128 characters\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/vector_stores/cassandra.ts","lineNumber":391,"sourceCode":"    }\n\n    return new driver.Client(clientConfig);\n  }\n\n  // Loaded dynamically: cassandra-driver is an optional peer dependency, so a static\n  // value import would break `import { Memory } from \"mem0ai/oss\"` for everyone else.\n  private async loadDriver(): Promise<any> {\n    const sdk = await loadPeer(\n      \"cassandra-driver\",\n      \"Cassandra vector store\",\n      () => import(\"cassandra-driver\"),\n    );\n    return sdk.default ?? sdk;\n  }\n\n  private validateIdentifier(name: string, label: string): string {\n    if (!SAFE_IDENTIFIER_RE.test(name)) {\n      throw new Error(\n        `Invalid ${label} '${name}': only letters, digits, and underscores are allowed, ` +\n          \"must start with a letter or underscore, and be at most 128 characters.\",\n      );\n    }\n    return name;\n  }\n\n  private cosineSimilarity(left: number[], right: number[]): number {\n    let dotProduct = 0;\n    let leftNorm = 0;\n    let rightNorm = 0;\n\n    for (let index = 0; index < left.length; index += 1) {\n      dotProduct += left[index] * right[index];\n      leftNorm += left[index] * left[index];\n      rightNorm += right[index] * right[index];\n    }\n","sourceCodeStart":373,"sourceCodeEnd":409,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/vector_stores/cassandra.ts#L373-L409","documentation":"Keyspace and table names are interpolated into CQL by the Cassandra store, so validateIdentifier() rejects anything that does not match SAFE_IDENTIFIER_RE: letters, digits, and underscores only; must start with a letter or underscore; at most 128 characters. This is an injection guard that runs before any CQL is built.","triggerScenarios":"Passing a collectionName, keyspace, or table name containing dashes, dots, spaces, or leading digits — e.g. collectionName: 'user-memories', 'mem0.prod', '2024logs' — to the Cassandra vector store config.","commonSituations":"Reusing a collection name from another vector store (Qdrant/Chroma allow dashes and dots); namespacing with dots like 'team.memory'; a name generated from user input that includes arbitrary characters.","solutions":["Rename the collection/identifier to use only [A-Za-z0-9_], starting with a letter or underscore, max 128 chars (e.g. 'user_memories' instead of 'user-memories')","If the name comes from user input, sanitize it (replace invalid chars with '_', prefix an underscore if it starts with a digit) before passing it in"],"exampleFix":"// before\nnew Cassandra({ collectionName: 'user-memories', ... });\n\n// after\nnew Cassandra({ collectionName: 'user_memories', ... });","handlingStrategy":"validation","validationCode":"const SAFE_ID = /^[A-Za-z_][A-Za-z0-9_]{0,127}$/;\nfunction safeCassandraName(name: string): string {\n  const cleaned = name.replace(/[^A-Za-z0-9_]/g, '_').replace(/^([0-9])/, '_$1');\n  if (!SAFE_ID.test(cleaned)) throw new Error(`Cannot sanitize name: ${name}`);\n  return cleaned;\n}","typeGuard":"const isSafeIdentifier = (n: string): boolean => /^[A-Za-z_][A-Za-z0-9_]{0,127}$/.test(n);","tryCatchPattern":null,"preventionTips":["Prefer underscores over dashes/dots in collection names from day one","Run user-provided names through a sanitizer before they reach the store config"],"tags":["cassandra","validation","sql-injection","configuration","typescript"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}