fix: add / back to isSafeId — node IDs contain file paths

Node IDs are generated as Label:filePath (e.g., Function:src/foo.ts:bar),
so forward slashes are expected in legitimate IDs. The over-tightened
regex was dropping all path-based IDs from Cypher queries.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
jreakin 2026-03-23 03:31:56 -05:00
parent 32c60d7f1a
commit f2f610b27d
2 changed files with 6 additions and 5 deletions

View file

@ -11,8 +11,8 @@ import { useAppState } from '../hooks/useAppState';
import { ProcessFlowModal } from './ProcessFlowModal';
import type { ProcessData, ProcessStep } from '../lib/mermaid-generator';
/** Validate that an ID contains only expected node identifier characters (no Cypher metacharacters, spaces, or slashes) */
const isSafeId = (id: string): boolean => /^[a-zA-Z0-9_:.\-]+$/.test(id);
/** Validate that an ID contains only expected node identifier characters (no Cypher metacharacters or spaces) */
const isSafeId = (id: string): boolean => /^[a-zA-Z0-9_:.\-/]+$/.test(id);
export const ProcessesPanel = () => {
const { graph, runQuery, setHighlightedNodeIds, highlightedNodeIds } = useAppState();

View file

@ -18,7 +18,7 @@ const validRelType = (t: string): boolean =>
(REL_TYPES as readonly string[]).includes(t);
const isSafeId = (id: string): boolean =>
/^[a-zA-Z0-9_:.\-]+$/.test(id);
/^[a-zA-Z0-9_:.\-/]+$/.test(id);
const isWriteQuery = (cypher: string): boolean =>
/\b(CREATE|DELETE|SET|MERGE|REMOVE|DROP|DETACH)\b/.test(cypher.toUpperCase());
@ -102,6 +102,8 @@ describe('isSafeId – identifier allowlist regex', () => {
['dotted name', 'Module:path.to.thing'],
['with hyphen', 'File:my-file.ts'],
['community id', 'comm_5'],
['file path id', 'File:src/index.ts'],
['nested path id', 'Function:src/utils/helpers.ts:doStuff'],
])('accepts valid ID: %s', (_desc, id) => {
expect(isSafeId(id)).toBe(true);
});
@ -109,8 +111,7 @@ describe('isSafeId – identifier allowlist regex', () => {
it.each([
['with spaces', 'Process:my process'],
['with @ symbol', 'Module:@scope/pkg'],
['with forward slash', 'File:src/index.ts'],
])('rejects ID with overly permissive chars: %s', (_desc, id) => {
])('rejects ID with unsafe chars: %s', (_desc, id) => {
expect(isSafeId(id)).toBe(false);
});