QWED

Type to search pages, engines and advisories.

    Looking for API details?Search the docs

    Security·Advisories·GHSA-45jv-2j44-4c2q

    SDK SQLGuard admits stacked statements, COPY TO PROGRAM, ATTACH and load_extension as verified read-only SQL

    highFixed in 8.0.0GHSA-45jv-2j44-4c2q · Published 26 October 2026

    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

    1. sqlglot.parse_one(sql) returns only the first expression, so SELECT 1; DROP TABLE users is checked as SELECT 1. Depending on the sqlglot version, it may also return an unparsed exp.Command.
    2. The guard is a denylist (Drop, Delete, Insert, Update, Alter, Create, TruncateTable). It does not cover Copy, Attach, Command, Pragma, Grant, or dangerous function calls.
    3. 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

    • qwed on PyPI: 3.0.1 to 7.3.0. SQLGuard and the local-first SDK path were added in fd863c8, first published in 3.0.1 (3.0.0 was not published to PyPI). Confirmed at runtime on 7.3.0.
    • The server's SQLVerifier in the same versions also admitted file and extension functions such as load_extension() and pg_read_file().

    Patches

    Fixed in 8.0.0 (53f1226):

    • QWEDClient.verify_sql (sync and async) always calls the server's /verify/sql, and is_verified follows the server's admission. A server that cannot be reached gives UNVERIFIABLE.
    • SQLVerifier denies a list of dangerous file, extension, network and command functions (DANGEROUS_SQL_FUNCTIONS in core/sql_verifier.py: load_extension, readfile, pg_read_file, lo_import, dblink, load_file, xp_cmdshell, utl_file and others) anywhere in a statement, as issue type dangerous_function.
    • SQLGuard accepts 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-017 and sql-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.

    All advisories