{"record":{"id":"0f5af9228233b732","repo":"paperclipai/paperclip","slug":"ctx-db-execute-target-must-be-inside-plugin-namesp","errorCode":null,"errorMessage":"ctx.db.execute target must be inside plugin namespace \"${namespace}\"","messagePattern":"ctx\\.db\\.execute target must be inside plugin namespace \"(.+?)\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/src/services/plugin-database.ts","lineNumber":294,"sourceCode":"export function validatePluginRuntimeExecute(query: string, namespace: string): void {\n  const statements = splitSqlStatements(query);\n  if (statements.length !== 1) {\n    throw new Error(\"Plugin runtime SQL must contain exactly one statement\");\n  }\n  const statement = statements[0]!;\n  assertNoBannedSql(statement);\n  const normalized = normaliseSql(statement);\n  if (!/^(insert\\s+into|update|delete\\s+from)\\b/.test(normalized)) {\n    throw new Error(\"ctx.db.execute only allows INSERT, UPDATE, or DELETE\");\n  }\n  if (/\\b(alter|create|drop|truncate)\\b/.test(normalized)) {\n    throw new Error(\"ctx.db.execute cannot contain DDL keywords\");\n  }\n\n  const refs = extractQualifiedRefs(statement);\n  const target = refs.find((ref) => [\"into\", \"update\", \"from\"].includes(ref.keyword));\n  if (!target || target.schema !== namespace) {\n    throw new Error(`ctx.db.execute target must be inside plugin namespace \"${namespace}\"`);\n  }\n  for (const ref of refs) {\n    if (ref.schema !== namespace) {\n      throw new Error(\"ctx.db.execute cannot reference public or other non-plugin schemas\");\n    }\n  }\n}\n\nfunction bindSql(statement: string, params: readonly unknown[] = []): SQL {\n  // Safe only after callers run the plugin SQL validators above.\n  if (params.length === 0) return sql.raw(statement);\n  const chunks: SQL[] = [];\n  let cursor = 0;\n  const placeholderPattern = /\\$(\\d+)/g;\n  const seen = new Set<number>();\n\n  for (const match of statement.matchAll(placeholderPattern)) {\n    const index = Number(match[1]);","sourceCodeStart":276,"sourceCodeEnd":312,"githubUrl":"https://github.com/paperclipai/paperclip/blob/120ae5428fa29bee300bcf806491cd4d965fbb7c/server/src/services/plugin-database.ts#L276-L312","documentation":"Namespace containment guard in validatePluginRuntimeExecute: after schema checks, the code rejects any qualified reference to a schema other than the plugin's namespace — executes may never target public or another plugin's schema. The cross-namespace write is at fault.","triggerScenarios":"Thrown at server/src/services/plugin-database.ts:294 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Target only tables inside the plugin namespace with ctx.db.execute."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"120ae5428fa29bee300bcf806491cd4d965fbb7c","analyzedAt":"2026-08-18T22:49:45.177Z","contentChangedAt":"2026-08-18T22:49:45.177Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}