{"record":{"id":"76d26782906ef29d","repo":"paperclipai/paperclip","slug":"plugin-runtime-sql-must-contain-exactly-one-statem","errorCode":null,"errorMessage":"Plugin runtime SQL must contain exactly one statement","messagePattern":"Plugin runtime SQL must contain exactly one statement","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/src/services/plugin-database.ts","lineNumber":253,"sourceCode":"  const allowedCoreReadTables = new Set(coreReadTables);\n  for (const ref of refs) {\n    if (ref.schema === namespace) continue;\n    if (ref.schema === \"public\") {\n      assertAllowedPublicRead(ref, allowedCoreReadTables);\n      continue;\n    }\n    throw new Error(`Plugin SQL references schema \"${ref.schema}\" outside namespace \"${namespace}\"`);\n  }\n}\n\nexport function validatePluginRuntimeQuery(\n  query: string,\n  namespace: string,\n  coreReadTables: readonly PluginDatabaseCoreReadTable[] = [],\n): 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 (!normalized.startsWith(\"select \") && !normalized.startsWith(\"with \")) {\n    throw new Error(\"ctx.db.query only allows SELECT statements\");\n  }\n  if (/\\b(insert|update|delete|alter|create|drop|truncate)\\b/.test(normalized)) {\n    throw new Error(\"ctx.db.query cannot contain mutation or DDL keywords\");\n  }\n\n  const allowedCoreReadTables = new Set(coreReadTables);\n  for (const ref of extractQualifiedRefs(statement)) {\n    if (ref.schema === namespace) continue;\n    if (ref.schema === \"public\") {\n      assertAllowedPublicRead(ref, allowedCoreReadTables);\n      continue;\n    }","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/paperclipai/paperclip/blob/120ae5428fa29bee300bcf806491cd4d965fbb7c/server/src/services/plugin-database.ts#L235-L271","documentation":"Runtime query guard in validatePluginRuntimeQuery: splitSqlStatements returned more or fewer than one statement. Multi-statement strings could smuggle mutations past per-statement checks, so ctx.db.query accepts exactly one statement; the multi-statement query string is at fault.","triggerScenarios":"Thrown at server/src/services/plugin-database.ts:253 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Split the plugin runtime SQL so each call contains exactly one statement."],"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"}