QWED

Type to search pages, engines and advisories.

    Looking for API details?Search the docs

    Security·Advisories·GHSA-p75q-7rg5-ff46

    CodeVerifier admits code that typing evaluates from strings: string annotations run by singledispatch.register, typing.get_type_hints and a ForwardRef's __forward_code__

    highFixed in 9.0.0GHSA-p75q-7rg5-ff46 · Published 6 November 2026

    Impact

    CodeVerifier.verify_code(code, "python") returns VERIFIED · ADMIT (is_valid: true, no issues) for Python code that hides an expression in a string which the typing machinery later compiles and runs. The verifier reads string constants only for critical names (exec, eval and the like), so an expression such as open('/etc/passwd').read() inside a string annotation or a forward reference is never examined as code.

    Code 8.0.0 9.0.0
    a function registered with functools.singledispatch .register whose parameter annotation is the string "open('/etc/passwd').read() or int" VERIFIED · ADMIT refused (dangerous_function)
    the same through functools.singledispatchmethod .register VERIFIED · ADMIT refused (dangerous_function)
    typing.get_type_hints(f) on a function with that annotation VERIFIED · ADMIT refused (dangerous_function)
    types.FunctionType(List["open('/etc/passwd').read()"].__args__[0].__forward_code__, {...})() VERIFIED · ADMIT refused (dangerous_attribute, dangerous_function)

    Controls: eval(input()) is refused (dangerous_function) and open('/etc/passwd').read() written as code is refused (file_or_network_access).

    .register without a class argument calls typing.get_type_hints on the function, which evaluates each string annotation in the module's globals during decoration. A ForwardRef compiles its string when it is created (List["..."] makes one), and __forward_code__ is that code object; types.FunctionType turns it into a function that runs it. With harmless payloads, all three routes ran on Python 3.10.20, 3.11.9 and 3.14.3.

    Libraries that resolve annotations with typing.get_type_hints when a function or class is decorated or defined evaluate string annotations the same way. No specific library was tested.

    A caller that runs code only after QWED admits it (an agent tool gate, a CI check, a sandbox pre-filter) will run the hidden expression.

    Affected

    qwed (PyPI) through 8.0.0. Reproduced on main @ 6ccca6eb; code_verifier.py is unchanged since v8.0.0.

    Reachable from:

    • POST /verify/code;
    • code items in POST /verify/batch;
    • CodeVerifier.verify_code and verify_python_deep;
    • the SDK paths that delegate to CodeVerifier.

    PR #560 (#534), also released in 9.0.0, refuses the explicit evaluators get_type_hints, evaluate_forward_ref, the eval_str keyword and Python 3.14's ForwardRef.evaluate(). On its own it does not cover the implicit routes above; the fix for this advisory does.

    Reproduction

    from qwed_new.core.code_verifier import CodeVerifier
    
    ANNOTATION = "\"open('/etc/passwd').read() or int\""
    cv = CodeVerifier()
    for code in [
        "from functools import singledispatch\n@singledispatch\ndef handle(x):\n    pass\n"
        f"@handle.register\ndef _(x: {ANNOTATION}):\n    pass",
        "import types\nfrom typing import List\n"
        "ref = List[\"open('/etc/passwd').read()\"].__args__[0]\n"
        "types.FunctionType(ref.__forward_code__, {\"open\": open})()",
        "open('/etc/passwd').read()",                                   # control
    ]:
        r = cv.verify_code(code, "python")
        print(r.status.value, r.developer_fields.get("is_valid"), [i.get("type") for i in r.developer_fields["issues"]])
    

    The first two print VERIFIED True []; the control prints VERIFIED False ['file_or_network_access']. The verifier only analyses the text; the runtime behaviour was confirmed separately with payloads that append to a list.

    Details

    src/qwed_new/core/code_verifier.py:

    • String constants are matched against the critical-name patterns only. Nothing parses a string that the typing machinery can turn into code: a string annotation (on a parameter, a return or an annotated assignment, nested ones included), a string inside a subscript (List["..."], which creates a ForwardRef), or a string given to typing.ForwardRef.
    • The AST checks (file and network access, process execution, the critical builtins) therefore never see the expression inside such a string.
    • __forward_code__ is not a dangerous attribute, and types.FunctionType is not refused when given a code object.

    Patches

    Fixed in 9.0.0 (f090717). Upgrade to 9.0.0 or later.

    • Every string typing may compile is parsed as an expression: anywhere in a parameter, return or variable annotation; directly in a subscript, or in a tuple or list there; and in the arguments of ForwardRef, TypeVar, NewType, ParamSpec, TypeVarTuple, TypeAliasType, the functional NamedTuple and TypedDict, and dataclasses.make_dataclass. Import aliases of these calls, and names assigned one, are recognised.
    • Such a string is refused when it holds a call, a lambda, a comprehension or generator, an assignment expression, await or yield, or a string that does (checked recursively; nesting deeper than 8 levels is refused). Names, attributes, subscripts and operators are admitted, so "List[int]" and row["first-name"] are unaffected.
    • __forward_code__, __forward_arg__, __annotations__, and Python 3.14's __annotate__ and __annotate_func__ are dangerous attributes.

    On 9.0.0 every row of the table above is refused (is_valid: false, BLOCKED).

    Workarounds

    Upgrade to 9.0.0. In any version, do not run code solely because verify_code admitted it; keep an OS-level sandbox (no filesystem, no network) as the primary control.

    Source

    Found while fixing #534 (PR #560), November 2026. The singledispatch.register route was posted by an automated reviewer (CodeRabbit) in a public review comment on PR #560 on 2026-11-02. The other routes have not been disclosed.

    All advisories