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.Attributecallees (os.system,subprocess.run,os.popen,shutil.rmtree) are never inspected.from os import systemis not inspected at all; onlyast.Importaliases are checked, and only for a warning.- Indirect access (
getattr(__builtins__, 'ev' + 'al'), dunder traversal,importlib) is not inspected. - The result is labelled
SAFEwith 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 in49213e4) through 7.3.0. qwed 2.0.xdoes not containQWEDLocal.verify_code.
Patches
Fixed in 8.0.0 (57fe523):
QWEDLocal.verify_codereturnsCodeVerifier's verdict, admitted byadmission_decision(): only admitted code isverifiedandSAFE.- Without
CodeVerifier(qwed_newis not installed), the result isUNVERIFIABLE, neverSAFE. - 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.
