Summary
execute_python_code checks the submitted code as text, then writes it to a script file and runs it with sys.executable. The interpreter decodes that file by its PEP 263 coding declaration (# coding: ... on the first two lines). Under a codec other than UTF-8 the text the interpreter reads is not the text that was checked. With # coding: utf-7, the sequence +AAo- decodes to a newline, so code written inside a comment becomes a statement that runs, and the code check never sees it.
Details
A minimal, harmless example:
# coding: utf-7
# +AAo-print('not checked')
print('checked')
The checker parses this as two comments and one print('checked') call. The interpreter decodes the file as UTF-7, reads the second line as an empty comment followed by print('not checked'), and runs both prints. Any statement can be hidden the same way, so the code check gives no assurance about what runs.
The tool runs only when the server administrator sets QWED_MCP_TRUSTED_CODE_EXECUTION=true. In that configuration, an MCP client (or text that reaches the model driving it) can run code the check would refuse, with the server user's privileges.
Affected versions
qwed-mcp 0.2.3 and earlier.
Fix
Fixed in 0.3.0 (PR #75):
- the code engine refuses a coding declaration that names any codec other than UTF-8, checking the first two lines under every way the tokenizer or
str.splitlines()can split them; - the script file is written as UTF-8 explicitly.
0.3.0 also replaces the 0.2.x denylist code check with an allowlist of modules, builtins and attributes. Other bypasses of the 0.2.x denylist were reported in public issues (for example #24), so upgrading is the remediation for the code check as a whole.
Workarounds
Leave QWED_MCP_TRUSTED_CODE_EXECUTION unset (the default) until you upgrade.
Disclosure
Found during maintainer review. Automated review comments on PR #75 described the issue publicly before this advisory was published.
