Postgresql Global Development Group
An issue exists where the AI Assistant's `execute sql query` tool fails to properly validate queries supplied by a Large Language Model (LLM). The tool uses `sqlparse` to ensure only one non-transaction-control statement is executed within a read-only transaction. However, a discrepancy between how `sqlparse` and PostgreSQL handle string-literal lexing allows an attacker to smuggle multiple statements. By using a backslash before a quote, an attacker can bypass the validator and execute unauthorized commands, such as `COMMIT` or `CREATE TABLE`, leading to security restriction bypass, data manipulation, or remote code execution. This is achievable via indirect prompt injection, where a malicious payload is placed in an object that the AI Assistant reads.