QWED

Type to search pages, engines and advisories.

    Looking for API details?Search the docs

    Security·Advisories·GHSA-v8qq-v427-qrqc

    QWEDLocal.verify_code reports os.system, subprocess and getattr-based code as verified SAFE

    highFixed in 8.0.0GHSA-v8qq-v427-qrqc · Published 26 October 2026

    Summary

    QWEDLocal.verify_code() decides safety with an AST check that flags only bare-name calls to eval, exec, compile and __import__. Attribute calls are never flagged, and importing os, subprocess or sys only adds a warning. Code such as import os; os.system(cmd) or subprocess.run(cmd, shell=True) comes back as verified=True, value="SAFE", confidence=1.0, and the CLI prints "SAFE CODE".

    This is a separate code path from QWEDClient.verify_code / CodeGuard (GHSA-4rj3-8wqj-cqwc), and has its own fix.

    Affected components

    Component Location
    QWEDLocal.verify_code qwed_sdk/qwed_local.py L1148-1200 (AST analysis and is_safe = len(dangerous_patterns) == 0)
    qwed CLI paths that call it qwed_sdk/cli.py (for example code_engine.verify_code(...) in qwed init and qwed test)

    Root cause

    if isinstance(node, ast.Call):
        if isinstance(node.func, ast.Name):
            if node.func.id in ['eval', 'exec', 'compile', '__import__']:
                dangerous_patterns.append(...)
    ...
    if alias.name in ['os', 'subprocess', 'sys']:
        warnings.append(...)          # warning only, does not affect is_safe
    is_safe = len(dangerous_patterns) == 0
    
    • ast.Attribute callees (os.system, subprocess.run, os.popen, shutil.rmtree) are never inspected.
    • from os import system is not inspected at all; only ast.Import aliases are checked, and only for a warning.
    • Indirect access (getattr(__builtins__, 'ev' + 'al'), dunder traversal, importlib) is not inspected.
    • The result is labelled SAFE with confidence 1.0, so a heuristic blocklist is presented as a verdict.

    Proof of concept (local, synthetic, inert payloads)

    from qwed_sdk import QWEDLocal
    
    local = QWEDLocal(base_url="http://localhost:11434/v1", model="llama3")  # verify_code does not call the LLM
    for code in [
        "import os\nos.system('echo hello')",
        "import subprocess\nsubprocess.run('echo hello', shell=True)",
        "from os import system\nsystem('echo hello')",
        "getattr(__builtins__, 'ev' + 'al')('1+1')",
    ]:
        r = local.verify_code(code)
        print(r.verified, r.value)   # True SAFE for each
    

    Run against 7.3.0 with network access blocked: all four print True SAFE; the control eval(user_input) prints False UNSAFE. main @ 4989490 has the same function.

    Impact

    Integrity of code admission. An application, agent or script that runs model-generated code only after QWEDLocal.verify_code(...).verified will run code that executes shell commands, deletes files or reaches eval. Attacker capability: control over the code being verified (model output). No credentials are needed.

    Affected versions

    • The check exists from tag v2.1.0 (introduced in 49213e4) through 7.3.0.
    • qwed 2.0.x does not contain QWEDLocal.verify_code.

    Patches

    Fixed in 8.0.0 (57fe523):

    • QWEDLocal.verify_code returns CodeVerifier's verdict, admitted by admission_decision(): only admitted code is verified and SAFE.
    • Without CodeVerifier (qwed_new is not installed), the result is UNVERIFIABLE, never SAFE.
    • Cached code results from the old check are not reused: the code-cache policy version is code_verifier-v2.

    Upgrade with pip install -U qwed (8.0.0 or later).

    Workarounds

    Use CodeVerifier().verify_code() from qwed_new.core.code_verifier and gate on admission_decision() instead of QWEDLocal.verify_code, and clear the QWEDLocal cache.

    All advisories