{"record":{"id":"1197257d58f763ce","repo":"FlowiseAI/Flowise","slug":"invalid-sql-statement-load-extension-is-not-allow","errorCode":null,"errorMessage":"Invalid SQL statement: load_extension is not allowed","messagePattern":"Invalid SQL statement: load_extension is not allowed","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/components/src/validator.ts","lineNumber":397,"sourceCode":"export const assertReadOnlySqlStatement = (sql: string): void => {\n    if (!sql || typeof sql !== 'string') {\n        throw new Error('Invalid SQL statement: statement is required and must be a string')\n    }\n\n    let trimmed = sql.trim()\n    // Strip at most one trailing semicolon (+ trailing whitespace)\n    trimmed = trimmed.replace(/;\\s*$/, '')\n\n    if (trimmed.includes(';')) {\n        throw new Error('Invalid SQL statement: multiple statements are not allowed')\n    }\n\n    if (!/^(SELECT|WITH)\\b/i.test(trimmed)) {\n        throw new Error('Invalid SQL statement: only read-only SELECT/WITH statements are allowed')\n    }\n\n    if (/load_extension\\s*\\(/i.test(trimmed)) {\n        throw new Error('Invalid SQL statement: load_extension is not allowed')\n    }\n}\n\n/**\n * Sanitize a file name to prevent path traversal attacks.\n * Strips common storage prefixes, extracts the basename, runs it through\n * the `sanitize-filename` package, and rejects anything that still looks unsafe.\n *\n * @param {string} name The file name to sanitize\n */\nexport const sanitizeFileName = (name: string): string => {\n    if (!name || typeof name !== 'string') {\n        throw new Error('Invalid file name: name is required')\n    }\n    // Strip the FILE-STORAGE:: prefix if present\n    let stripped = name.replace(/^FILE-STORAGE::/, '')\n    // Decode percent-encoded traversal sequences before basename extraction\n    try {","sourceCodeStart":379,"sourceCodeEnd":415,"githubUrl":"https://github.com/FlowiseAI/Flowise/blob/abe4a8601a058047b350c260676826e21dd14101/packages/components/src/validator.ts#L379-L415","documentation":"Thrown by assertReadOnlySqlStatement (packages/components/src/validator.ts:397) when the statement contains 'load_extension(' (case-insensitive). SQLite's load_extension lets a query load arbitrary native code into the process; even though the statement may start with SELECT, this guard blocks the function call to prevent code execution via a malicious DB/LLM.","triggerScenarios":"The SQL contains a call like \"SELECT load_extension('/tmp/evil')\" — typically from a malicious LLM response or an attacker-controlled .sqlite file with crafted views/triggers that emit such SQL.","commonSituations":"Security testing/fuzzing of the chain; loading a DB file from an untrusted source; a prompt-injection payload crafting the call.","solutions":["Remove the load_extension call — Flowise does not allow it.","Treat any LLM output containing load_extension as a prompt-injection attempt and reject the turn.","Only ingest .sqlite files from trusted sources.","Compile SQLite without load_extension support for defense-in-depth."],"exampleFix":"// before\nsql = \"SELECT load_extension('/tmp/evil')\"\n\n// after\nsql = 'SELECT name FROM sqlite_master WHERE type = \\'table\\''   // benign introspection","handlingStrategy":"validation","validationCode":"if (/load_extension\\s*\\(/i.test(String(sql ?? ''))) throw new Error('load_extension rejected (possible prompt injection)');\nassertReadOnlySqlStatement(sql);","typeGuard":"const isFreeOfLoadExtension = (s: unknown): s is string => typeof s === 'string' && !/load_extension\\s*\\(/i.test(s);","tryCatchPattern":"try { assertReadOnlySqlStatement(sql) } catch (e) { if (e instanceof Error && /load_extension/.test(e.message)) { /* treat as prompt injection: abort turn */ throw new SecurityError('load_extension attempt blocked') } else throw e }","preventionTips":["Treat any load_extension in LLM output as prompt injection and reject the turn.","Only open .sqlite files from trusted sources.","Compile SQLite without load_extension for defense-in-depth.","Log and alert on this error so attacks are visible."],"tags":["sql","security","validation","code-execution","load-extension","sqlite","database","llm","prompt-injection","flowise"],"backgroundTag":null,"analyzedSha":"abe4a8601a058047b350c260676826e21dd14101","analyzedAt":"2026-08-12T16:04:40.823Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}