Skip to content

Commit e75f7e6

Browse files
fix(safe_eval): remove parent-side deserialization sink (v0.0.7)
Reported by Juan Lucas Armendares (Sunplace Solutions): in 0.0.6 the child serialized its evaluation result with cloudpickle and the parent called cloudpickle.loads() on it with full builtins. The AST checker only guarded what ran inside the sandboxed child, never the value sent back, so an expression could return a __reduce__ gadget that executed arbitrary code in the calling process. Distinct root cause from CVE-2026-133467. Result boundary - No pickle on the evaluation path at all: the child encodes the result as plain primitives over a multiprocessing.Pipe and the parent rebuilds it with a non-executable decoder. - Results are plain data (None, bool, int, float, complex, str, bytes, Decimal, Fraction); containers are opt-in via the new allow_objects flag. Lambdas, classes, modules, generators and user types now raise RuntimeError instead of being serialized. - Exceptions cross as (builtin type name, message); SystemExit / KeyboardInterrupt / GeneratorExit arrive as catchable RuntimeError and user-defined exception types are never reconstructed in the parent. - Bounded results (depth, node count, byte size) and a per-call int->str digit cap keep a returned value from burning CPU in the caller. - The Pipe is drained by a reader thread so a result larger than the OS pipe buffer cannot deadlock the parent; timeout latency tightened. - cloudpickle dependency removed. AST checker hardening (same audit) - Format/format_map templates that name attributes or keys are rejected ('{0.__init__.__globals__}'.format(obj) is an invisible attribute read). - Rebound safe-builtin names may only be called when explicitly allowlisted ((len := f)(), [f() for len in [..]], (lambda len: len())(f)). - Callables passed to builtins that invoke them (sorted(key=...), iter(f, None)) follow the same allowlist; allowed_vars entries are data, not call grants. - __builtins__ and the other reserved names are never resolvable or rebindable. - file_access/network_access are enforced after allowed_builtins is merged, so re-introducing open through allowed_builtins no longer bypasses the flag. Tests: 108 passing (29 new in TestResultBoundaryV007 plus updated result-policy assertions). Docs, SECURITY.md and the advisory draft updated for 0.0.7. Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
1 parent d2ff49d commit e75f7e6

7 files changed

Lines changed: 1126 additions & 119 deletions

File tree

‎.github/workflows/test.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
# dependencies are required.
4141
run: |
4242
python -m pip install --upgrade pip
43-
python -m pip install "cryptography>=41" "cloudpickle>=2.2"
43+
python -m pip install "cryptography>=41"
4444
4545
- name: Run test suite
4646
run: python -m unittest test.py test_poc_vulnerability.py -v

‎README.md‎

Lines changed: 60 additions & 9 deletions
Large diffs are not rendered by default.

‎SECURITY.md‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ We ask that you give us reasonable time to release a fix before any public discl
3232

3333
| Version | Supported |
3434
| :--- | :--- |
35-
| 0.0.6 and later | ✅ Yes |
36-
| 0.0.5 | ⚠️ Known issue — see [GHSA-m85r-gp57-6p5q](https://github.com/Infinitode/CodeSafe/security/advisories/GHSA-m85r-gp57-6p5q); upgrade to 0.0.6 |
35+
| 0.0.7 and later | ✅ Yes |
36+
| 0.0.6 | ⚠️ Known critical issue — the `safe_eval()` result is deserialized in the caller (remote code execution); fixed in 0.0.7 |
37+
| 0.0.5 | ⚠️ Known issue — see [GHSA-m85r-gp57-6p5q](https://github.com/Infinitode/CodeSafe/security/advisories/GHSA-m85r-gp57-6p5q); upgrade to 0.0.7 |
3738
| 0.0.1 – 0.0.4 | ❌ No — critical sandbox escape, [CVE-2026-133467](https://github.com/Infinitode/CodeSafe/security/advisories/GHSA-7gp8-3j6q-v4h8) |
3839

3940
Only the latest release receives fixes. Please upgrade rather than report issues that may already be fixed.
@@ -44,14 +45,15 @@ Only the latest release receives fixes. Please upgrade rather than report issues
4445
| :--- | :--- | :--- | :--- |
4546
| `safe_eval` sandbox escape via indirect subscript call | CVE-2026-133467 · [GHSA-7gp8-3j6q-v4h8](https://github.com/Infinitode/CodeSafe/security/advisories/GHSA-7gp8-3j6q-v4h8) | 0.0.1 - 0.0.4 | 0.0.5 |
4647
| `safe_eval` sandbox escape via dunder attribute string-argument (`allow_attributes=True`) | [GHSA-m85r-gp57-6p5q](https://github.com/Infinitode/CodeSafe/security/advisories/GHSA-m85r-gp57-6p5q) · CVE pending | 0.0.3 - 0.0.5 | 0.0.6 |
48+
| Remote code execution in the calling process via unsafe deserialization of the `safe_eval()` result | GHSA to be assigned · CVE pending | 0.0.6 | 0.0.7 |
4749

4850
See https://github.com/Infinitode/CodeSafe/security/advisories for the canonical list.
4951

5052
## Scope notes
5153

5254
CodeSafe contains two very different components, and reports are welcome for both, but keep in mind:
5355

54-
- **`safe_eval()`** is a best-effort sandbox, not a hard security boundary. Reports demonstrating escapes under documented usage are very much in scope. Reports that require you to defeat host-level isolation (containers, seccomp, etc.) are out of scope.
56+
- **`safe_eval()`** is a best-effort sandbox, not a hard security boundary. Reports demonstrating escapes under documented usage are very much in scope. Reports that require you to defeat host-level isolation (containers, seccomp, etc.) are out of scope. Since 0.0.7 the evaluation result is data-only and never deserialized with pickle, so "the result object's `__reduce__` runs in the caller" is no longer reachable; being unable to return lambdas/classes is a documented limitation, not a vulnerability.
5557
- **Encryption** protects code at rest. The built-in default key is public by design; only payloads encrypted with a user-supplied key can be confidential (see [Security Limitations & Notes](README.md#security-limitations--notes)). Reports of integrity/confidentiality failures in the v2 format (wrong key accepted, tampered payload decrypting successfully) are in scope; "the default key is public" is by design, not a vulnerability.
5658

5759
Thank you for helping make CodeSafe safer!

0 commit comments

Comments
 (0)