Impact
CodeVerifier.verify_code returns VERIFIED, is_valid: true and admission ADMIT for Python that runs a shell command through the module loader object every module has. POST /verify/code returns the same verdict.
code |
main @ b74ac00 |
Correct |
|---|---|---|
__loader__.load_module('posix').system('id') |
VERIFIED, is_valid: true, ADMIT |
unsafe (runs id) |
__spec__.loader.load_module('posix').system('id') |
VERIFIED, is_valid: true, ADMIT |
unsafe |
import os; os.system('id') (control) |
VERIFIED, is_valid: false, BLOCKED |
correct |
__loader__ is the module's BuiltinImporter/SourceFileLoader. load_module('posix') returns the posix module, so the call is os.system without an import statement or a name the denylist knows.
The false verdict is in the result: CodeGuard and the sandbox's own pattern check do block .system, so QWED does not run this code itself. A caller that gates execution on /verify/code's admission would.
Affected
qwed (PyPI) through 8.0.0. Reproduced on main @ b74ac00.
Reachable from:
POST /verify/code;- the
CodeVerifier.verify_codePython API.
Reproduction
from qwed_new.core.code_verifier import CodeVerifier
from qwed_new.core.diagnostics import admission_decision
cv = CodeVerifier()
for code in ["__loader__.load_module('posix').system('id')",
"__spec__.loader.load_module('posix').system('id')",
"import os\nos.system('id')"]:
dr = cv.verify_code(code, language="python")
print(repr(code), dr.status.value, dr.developer_fields.get("is_valid"), admission_decision(dr).value)
Details
src/qwed_new/core/code_verifier.py:313:PYTHON_DANGEROUS_ATTRSdoes not list__loader__,__spec__,loaderorload_module.- The checks that catch
os.systemlook for a module the snippet imported or a known dangerous name.__loader__is neither: it is a module global that needs no import, andload_moduletakes the module name as a string. - The same class as GHSA-4phf-6h72-9xfg and GHSA-jrxf-9jh4-86w7 (a dangerous capability reached through an object the denylist does not model).
Patches
Fixed in 9.0.0 (4cd0574). Upgrade to 9.0.0 or later.
__loader__and__spec__are dangerous attributes.- The loader methods and import-system internals that return a module by name (
load_module,create_module,module_from_specand the importlib bootstrap functions and modules) are refused wherever they appear: called or not, as an attribute, an import or alias, or a string. pkgutil.resolve_nameandpydoc.locateare refused, with import aliases resolved.- Any read of
sys.modulesis refused, not only a subscript (sys.modules.get(...),from sys import modules).
On 9.0.0 both rows of the table above are VERIFIED, is_valid: false, BLOCKED (dangerous_attribute, dangerous_function).
