Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(semgrep): fixed-literal ANN definition regex with table allowlist check; annotate comparison-only realpath in pushStatusForWorkspace
garrytan400b14e33d2f
diff --git a/src/core/embedding-ann-build.ts b/src/core/embedding-ann-build.tsindex bdb4049904..1168bce720 100644--- a/src/core/embedding-ann-build.ts+++ b/src/core/embedding-ann-build.ts@@ -24,11 +24,7 @@ export interface DeferredAnnIndex { name: string; def: string }export const ANN_BUILD_MESSAGE = 'building vector index after re-embed (search runs unindexed until done)';-function safeAnnDef(tables: readonly string[]): RegExp {- const names = tables.filter(t => /^[a-z_][a-z0-9_]*$/.test(t)).join('|');- return new RegExp(`^CREATE INDEX (?:IF NOT EXISTS )?([a-z_][a-z0-9_]{0,62}) ON (?:public\\.)?(?:${names}) USING hnsw \\(embedding (?:vector|halfvec)_(?:cosine|l2|ip)_ops\\)`- + `(?: WITH \\([a-z_]+ ?= ?'?[0-9]+'?(?:, ?[a-z_]+ ?= ?'?[0-9]+'?)*\\))?(?: WHERE [A-Za-z0-9_ ().,:<>=!'-]+)?$`);-}+const ANN_DEF = /^CREATE INDEX (?:IF NOT EXISTS )?([a-z_][a-z0-9_]{0,62}) ON (?:public\.)?([a-z_][a-z0-9_]*) USING hnsw \(embedding (?:vector|halfvec)_(?:cosine|l2|ip)_ops\)(?: WITH \([a-z_]+ ?= ?'?[0-9]+'?(?:, ?[a-z_]+ ?= ?'?[0-9]+'?)*\))?(?: WHERE [A-Za-z0-9_ ().,:<>=!'-]+)?$/;/*** Only HNSW definitions over the `embedding` column of the given tables are@@ -37,11 +33,11 @@ function safeAnnDef(tables: readonly string[]): RegExp {*/export function parseDeferredAnnIndexes(raw: unknown, tables: readonly string[] = ['content_chunks']): DeferredAnnIndex[] {if (!Array.isArray(raw)) return [];- const pattern = safeAnnDef(tables);return raw.flatMap((entry): DeferredAnnIndex[] => {if (!entry || typeof entry.name !== 'string' || typeof entry.def !== 'string' || entry.def.includes(';')) return [];const def = entry.def.replace(/\s+/g, ' ').trim();- return pattern.exec(def)?.[1] === entry.name ? [{ name: entry.name, def }] : [];+ const match = ANN_DEF.exec(def);+ return match && match[1] === entry.name && tables.includes(match[2]!) ? [{ name: entry.name, def }] : [];});}diff --git a/src/core/workspace-push.ts b/src/core/workspace-push.tsindex 2c46f9969a..368fc8970d 100644--- a/src/core/workspace-push.ts+++ b/src/core/workspace-push.ts@@ -502,6 +502,7 @@ export function readPushStatusForRoot(root: string): PushStatusEntry | null {* is never reported as this workspace's push state.*/export function pushStatusForWorkspace(entries: readonly PushStatusEntry[], ws: string): PushStatusEntry | null {+ // nosemgrep: javascript.lang.security.audit.path-traversal.path-join-resolve-traversal.path-join-resolve-traversal -- comparison only: normalizes the operator's own push-status repoRoot and workspace path to compare them; nothing is read or written at the resolved pathconst real = (p: string) => { try { return realpathSync(p); } catch { return resolve(p); } };const target = real(ws);const own = entries.find((e) => e.repoRoot !== undefined && real(e.repoRoot) === target);