Impact
GHSA-qgjc-92m3-fcr6 (9.0.0) moved /verify/math into worker processes with a time limit and a memory limit, and kills a worker that runs too long. Two other routes still evaluate a maths expression with SymPy in the API process:
POST /verify/consensus:ConsensusVerifier._verify_with_math(src/qwed_new/core/consensus_verifier.py:823-830) callsVerificationEngine.verify_mathon a thread of a plainThreadPoolExecutor. The consensus deadline stops waiting for the engine, but nothing stops the thread.POST /verify/natural_languageandPOST /agents/{agent_id}/verify:ControlPlane.process_natural_language(src/qwed_new/core/control_plane.py:310) callsverify_mathsynchronously inside the coroutine, on the event loop.
The expression is the model's translation of the caller's question. An expression the worker has to cancel, such as 2**((10000*x/x)**9) from the GHSA-qgjc tests, runs in CPython's big-integer arithmetic, which holds the interpreter lock until it finishes. Every other request on the process waits; on the natural-language route the event loop itself stops.
Checked on main @ 6cb53f00 (11.0.0): with VerificationEngine().verify_math("2**((10000*x/x)**9)", 1) running on a thread, the main thread's time.sleep(1) had not returned after 40 seconds. Through the math worker the same expression is UNVERIFIABLE once its time limit passes (tests/test_ghsa_qgjc_math_worker.py, CANCELLING).
Not shown: a real provider translating a question into such an expression. The translation asks the model to write the question's arithmetic as an expression, so a question that states the expression is the likely way.
Affected
qwed (PyPI) through 12.0.0, the API server. Before 9.0.0 every maths route evaluated in process (GHSA-qgjc-92m3-fcr6); from 9.0.0 these three routes still do.
Reproduction
import threading
import time
from qwed_new.core.verifier import VerificationEngine
engine = VerificationEngine()
engine.verify_math("1 + 1", 2) # warm SymPy
threading.Thread(target=engine.verify_math, args=("2**((10000*x/x)**9)", 1), daemon=True).start()
started = time.monotonic()
time.sleep(1) # returns only when the SymPy thread lets go of the interpreter lock
print(round(time.monotonic() - started))
Details
The worker covers only the /verify/math route (src/qwed_new/api/main.py:1076, run_math_async). ConsensusVerifier and ControlPlane each hold their own VerificationEngine and call it directly, so they have none of the worker's limits.
Patches
Fixed in 13.0.0. Upgrade with pip install -U "qwed>=13.0.0". /verify/natural_language, /agents/{agent_id}/verify and /verify/consensus evaluate maths in the math worker, under QWED_MATH_TIMEOUT_SECONDS, QWED_MATH_WORKERS, QWED_MATH_MAX_WAITING and QWED_MATH_WORKER_MEMORY_MB: a run past the time limit is UNVERIFIABLE (math.timeout), and a full pool is refused (math.capacity). ControlPlane.math_verifier and ConsensusVerifier.math_verifier are removed.
Workarounds
Do not expose /verify/consensus, /verify/natural_language or /agents/{agent_id}/verify to untrusted callers, and run more than one API process behind a health check that restarts a stalled one.
Advisory page: https://qwedai.tech/security/advisories/ghsa-hhxx-56wq-4j82
