Summary
QWEDClient.verify_sql() uses the local SQLGuard whenever qwed_new is importable, instead of the hardened server-side SQLVerifier. SQLGuard parses only the first statement (sqlglot.parse_one) and checks it against a short mutation denylist. Stacked statements, COPY ... TO PROGRAM, ATTACH DATABASE, load_extension() and file-read functions are all reported as verified: True ("SQL Query verified safe and syntax-valid").
Affected components
| Component | Location |
|---|---|
SQLGuard.verify_query |
src/qwed_new/guards/sql_guard.py |
QWEDClient.verify_sql (local-first, API only on ImportError) |
qwed_sdk/client.py ~L232-265 |
Any agent or MCP integration that calls SQLGuard directly |
Caller code |
Root cause
sqlglot.parse_one(sql)returns only the first expression, soSELECT 1; DROP TABLE usersis checked asSELECT 1. Depending on the sqlglot version, it may also return an unparsedexp.Command.- The guard is a denylist (
Drop, Delete, Insert, Update, Alter, Create, TruncateTable). It does not coverCopy,Attach,Command,Pragma,Grant, or dangerous function calls. - Function calls are not inspected at all.
Proof of concept (local, synthetic)
from qwed_new.guards.sql_guard import SQLGuard
g = SQLGuard()
for q in ["SELECT 1; DROP TABLE users",
"COPY users TO PROGRAM 'id'",
"ATTACH DATABASE 'x' AS y",
"SELECT load_extension('x')",
"SELECT pg_read_file('/etc/passwd')"]:
print(q, g.verify_query(q, "sqlite")["verified"]) # all True
Observed on 7.3.0 and main @ 52d3e06. A single DROP TABLE users is correctly rejected; the bypass needs stacking or an unlisted statement or function.
Impact
Integrity of SQL admission. A consumer that runs LLM-generated SQL only after verify_sql(...).is_verified (the read-only guarantee SQLGuard advertises) can be led to run destructive statements, load extensions, read server files or (PostgreSQL COPY ... TO PROGRAM) run OS commands. The actual effect depends on the database driver: many drivers reject multi-statement strings, while executescript, psql or some MySQL settings accept them. Attacker capability: control over the generated SQL. No credentials are needed.
Affected versions
qwedon PyPI: 3.0.1 to 7.3.0.SQLGuardand the local-first SDK path were added infd863c8, first published in 3.0.1 (3.0.0 was not published to PyPI). Confirmed at runtime on 7.3.0.- The server's
SQLVerifierin the same versions also admitted file and extension functions such asload_extension()andpg_read_file().
Patches
Fixed in 8.0.0 (53f1226):
QWEDClient.verify_sql(sync and async) always calls the server's/verify/sql, andis_verifiedfollows the server's admission. A server that cannot be reached givesUNVERIFIABLE.SQLVerifierdenies a list of dangerous file, extension, network and command functions (DANGEROUS_SQL_FUNCTIONSincore/sql_verifier.py:load_extension,readfile,pg_read_file,lo_import,dblink,load_file,xp_cmdshell,utl_fileand others) anywhere in a statement, as issue typedangerous_function.SQLGuardaccepts exactly one statement, allows only a read-only root, rejects administrative and destructive statements anywhere in the tree (the server's sets),SELECT ... INTO, MySQL executable comments and the same dangerous functions, and fails closed on parse errors.- The soundness eval reproduces the server part (
evals/cases/sql.json,sql-017andsql-018).
Upgrade with pip install -U qwed (8.0.0 or later).
Workarounds
Call the server's /verify/sql directly and gate on admission == "ADMIT", and run generated SQL with a database user that has no file, extension or program-execution privileges.
Related
GHSA-6p94-4f75-g2wq, GHSA-6cpx-8jrq-r7h3, GHSA-q5g6-6cw2-cjm3 (server SQLVerifier). The companion CodeGuard finding is GHSA-4rj3-8wqj-cqwc.
