QWED

Type to search pages, engines and advisories.

    Looking for API details?Search the docs

    Security·Advisories·GHSA-jvhg-jw63-gr5g

    SQLVerifier admits tautologies built with IN, IS, LIKE, BETWEEN, division, concatenation, CAST, COALESCE and function calls (incomplete fix of GHSA-6cpx-8jrq-r7h3)

    mediumFixed in 9.0.0GHSA-jvhg-jw63-gr5g · Published 6 November 2026

    Impact

    SQLVerifier.verify_sql returns VERIFIED · ADMIT for queries whose WHERE clause contains an always-true predicate written with an operator the constant folder does not handle. These are classic injection shapes: a filter like id = 5 is widened to every row.

    GHSA-6cpx-8jrq-r7h3 (7.3.0) replaced the fixed list of tautology shapes with value-level folding (_const_eval). The folding covers literals, NOT/AND/OR, the six comparisons and + - *. Any other node raises _NotConstant and the predicate is treated as not constant, so these are still admitted on 8.0.0:

    Predicate after WHERE id=5 8.0.0
    OR 1 IN (1) VERIFIED · ADMIT
    OR NULL IS NULL, OR 1 IS NOT NULL VERIFIED · ADMIT
    OR 'a' LIKE 'a' VERIFIED · ADMIT
    OR 1 BETWEEN 0 AND 2 VERIFIED · ADMIT
    OR 2/1=2, OR 2 % 2 = 0 VERIFIED · ADMIT
    OR 'a'||'b'='ab' VERIFIED · ADMIT
    OR COALESCE(1,0)=1, OR CAST(1 AS INT)=1, OR ABS(-1)=1 VERIFIED · ADMIT
    OR EXISTS (SELECT 1) VERIFIED · ADMIT
    WHERE NOT (id=5 AND 1=0) VERIFIED · ADMIT
    OR 1=1, OR TRUE, OR 'x'='x' (controls) blocked

    NOT (id=5 AND 1=0) is admitted because AND does not short-circuit on a constant-false operand when the other operand references a column.

    The same result comes back on the sqlite dialect (the /verify/sql default) and through CodeVerifier.verify_code(..., language="sql").

    Affected

    qwed (PyPI) 7.3.0 to 8.0.0, from the GHSA-6cpx fix onwards; earlier releases are affected through GHSA-6cpx itself. Reproduced on main @ 10f5627 (the SQL code is unchanged since 8.0.0).

    Reachable from POST /verify/sql, SQL items in POST /verify/batch, POST /verify/code with language: sql, and the SQLVerifier / CodeVerifier Python API.

    Reproduction

    from qwed_new.core.sql_verifier import SQLVerifier
    
    v = SQLVerifier()
    ddl = "CREATE TABLE users (id INT, name TEXT);"
    for q in ["SELECT name FROM users WHERE id=5 OR 1 IN (1)",
              "SELECT name FROM users WHERE id=5 OR NULL IS NULL",
              "SELECT name FROM users WHERE NOT (id=5 AND 1=0)",
              "SELECT name FROM users WHERE id=5 OR 1=1"]:          # control
        r = v.verify_sql(q, ddl, "postgres")
        print(r.status.value, r.developer_fields.get("is_valid"), [i["type"] for i in r.developer_fields["issues"]])
    

    The first three print VERIFIED True []. The control prints VERIFIED False ['injection_tautology', 'injection_or_true'].

    Details

    • src/qwed_new/core/sql_verifier.py, _const_eval (lines 118-163): the fold covers Paren, Boolean, Null, Literal, Neg, Not, And, Or, six comparison classes, Add, Sub and Mul. In, Is, Like/ILike, Between, Div, Mod, DPipe, Coalesce, Cast, Exists and function calls raise _NotConstant.
    • And folds only when both sides fold, so col = 5 AND <constant false> is never reduced to false, and its negation is never seen as always true.
    • The tautology checks that use the fold (around lines 634-665) treat _NotConstant as "not a tautology" and add no issue, so the result maps to ADMIT.

    Patches

    Fixed in 9.0.0 (455341e). Upgrade to 9.0.0 or later.

    • The constant folder covers every column-free operator in the table: IN, IS [NOT] NULL, IS TRUE/FALSE, LIKE/ILIKE, BETWEEN, /, %, ||, IS [NOT] DISTINCT FROM, COALESCE, CAST, ABS, and EXISTS over a SELECT with no FROM. It folds only where database engines agree: an inexact division, a string compared with a number, two different strings, a LIKE whose result depends on case, and a cast whose result differs between engines are not folded.
    • AND with a constant-false operand and OR with a constant-true operand fold, whatever the other side reads.
    • A column compared with itself (=, >=, <=, IS NOT DISTINCT FROM) is always true; see the addendum.
    • Fail closed: a predicate in WHERE, HAVING or JOIN … ON that reads no data and still cannot be folded is not admitted (unevaluated_constant_predicate, constraint sql_verifier.unevaluated_predicate). For example, id = 5 OR 'a' = 'b' is now refused.
    • CodeVerifier.verify_code(..., language="sql") runs the same checks.

    On 9.0.0 every row of the table and of the addendum is VERIFIED, is_valid: false, BLOCKED, on the postgres and sqlite dialects.

    As with GHSA-6cpx, this is a screening aid; parameterised queries and least-privilege database accounts remain the primary control.

    Source

    Internal correctness audit (October 2026). Not previously disclosed.

    Addendum (re-checked on main @ b74ac00)

    One more shape that the constant folder does not cover: a column compared with itself.

    WHERE clause main @ b74ac00 Correct
    id = 5 OR id = id VERIFIED · ADMIT tautology (true for every non-NULL id)
    id = 5 OR 1 IN (1,2) VERIFIED · ADMIT tautology (already listed above)
    id = 5 OR 1=1 (control) VERIFIED, is_valid: false, BLOCKED correct

    x = x is not column-free, so extending _const_eval to the remaining operators does not catch it. 9.0.0 adds the rule it needs: a comparison whose two sides are the same column reference (=, >=, <=, IS NOT DISTINCT FROM) is a tautology over non-NULL rows.

    All advisories