You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 3ba2bb1
Browse filesBrowse the repository at this point in the historyBrowse files
Release v0.0.6: security hardening, bug fixes, packaging & CI modernization
Security:
- Block ALL attribute names starting with __ (was a hardcoded dunder list),
closing a sandbox-escape bypass where dunders were read through string
arguments, e.g. ().__getattribute__('__class__') with allow_attributes=True
- Always terminate the evaluation child on timeout; immediate_termination=False
previously leaked unkillable CPU-spinning processes (now deprecated)
- Remove dir() and id() from the default safe builtins
Bug fixes:
- Serialize eval results synchronously in the child via pickle; unpicklable
results (lambdas, generators, mappingproxy) now raise a clear RuntimeError
instead of a misleading EvaluationTimeoutError from the queue.empty() race
- encrypt() fails loudly on characters outside the mapping alphabet instead of
silently corrupting non-ASCII code; custom mapping values validated to be
exactly 64 characters
- decrypt() validates Base64 input (validate=True); whitespace-tolerant
- Non-positive timeout values rejected with ValueError
- run() executes decrypted code with __name__='__main__' in an isolated namespace
- Explicit UTF-8 for all file I/O; exception chaining; original exception types
propagate from child processes; anchored '# <base64>' extraction regex
Packaging/CI:
- New PEP 621 pyproject.toml (SPDX MIT) - pip install/python -m build now work
from a fresh checkout (was {{VERSION_PLACEHOLDER}}, an invalid version)
- Publish workflow fixed (deprecated set-output, @master actions), added
tag<->version consistency check; added test.yml (py3.8-3.12, linux/win/mac)
Docs/tests:
- CVE-2026-133467 referenced in changelog (was 'CVE pending')
- README, supported Python versions (>=3.8), v0.0.6 changelog
- New SECURITY_AUDIT.md with full findings and remediation notes
- 73 tests passing; test_security_error_on_unsafe_function can no longer pass silently
Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
@@ -18,55 +18,79 @@ An open-source Python library for code encryption, decryption, and safe evaluati
18
18
19
19
**Versions 0.0.1 through 0.0.4 contain a known sandbox escape vulnerability in `safe_eval()` that allows arbitrary code execution.**
20
20
21
-
See the security advisory: https://github.com/Infinitode/CodeSafe/security/advisories/GHSA-7gp8-3j6q-v4h8 (CVE ID: CVE-2026-133467)
21
+
See the security advisory: https://github.com/Infinitode/CodeSafe/security/advisories/GHSA-7gp8-3j6q-v4h8 (CVE ID: CVE-2026-133467 · CVSS 3.1 score: 9.8)
22
22
23
23
-**Vulnerability**: The `safe_eval()` function in versions 0.0.1-0.0.4 is vulnerable to a sandbox escape via indirect subscript lookup (e.g., `__builtins__['exec'](...)`). This bypasses the AST validation and allows execution of arbitrary Python code.
24
24
-**Impact**: An attacker controlling an expression passed to `safe_eval()` can execute arbitrary Python code with the application's permissions.
**If you are using any version from 0.0.1 to 0.0.4, you should upgrade to version 0.0.5 or later immediately.** These earlier versions should **not** be used in untrusted expression evaluation environments.
28
+
**If you are using any version from 0.0.1 to 0.0.4, you should upgrade to version 0.0.6 or later immediately.** These earlier versions should **not** be used in untrusted expression evaluation environments.
29
29
30
30
The fix includes:
31
31
1. Rejecting all `ast.Call` nodes unless the exact target is explicitly whitelisted (including calls via subscript, attribute, and other indirect targets)
32
32
2. Using a minimal built-ins allowlist that excludes dangerous functions like `exec`, `eval`, `compile`, and `__import__`
33
33
3. Added comprehensive regression tests for indirect call targets
34
34
35
+
Version **0.0.6** additionally closes a second, related sandbox issue (details in the v0.0.6 changelog and [SECURITY_AUDIT.md](SECURITY_AUDIT.md)): with `allow_attributes=True`, dunder attributes such as `__class__` could be read indirectly through string arguments (e.g., `().__getattribute__('__class__')`), bypassing the dunder blocklist. All attribute names starting with `__` are now always rejected.
36
+
35
37
A huge thanks to [@hkmj19](https://github.com/hkmj19)/[Linkedin](https://www.linkedin.com/in/hemanth-kumar-mj-24b50a256/) for finding and reporting this vulnerability.
> These tests are only available on GitHub, and not on PyPI. They are external tests that aren't built along with `CodeSafe` versions.
41
43
42
-
CodeSafe v0.0.5+ includes a rigorous test suite (`TestVulnerabilityFixes`and `TestEdgeCases` in `test_poc_vulnerability.py`) to systematically verify that `safe_eval` blocks sandbox escapes while preserving standard evaluation features.
44
+
CodeSafe v0.0.6 includes a rigorous test suite (`TestVulnerabilityFixes`, `TestEdgeCases`and `TestHardeningRegression` in `test_poc_vulnerability.py`, plus `test.py`) to systematically verify that `safe_eval` blocks sandbox escapes while preserving standard evaluation features.
43
45
44
46
### Test Results Summary
45
47
46
-
**49/49 Security & Edge Case Tests Passing** (`100% Pass Rate` across all vector categories)
48
+
**73/73 Tests Passing** (`100% Pass Rate` across all vector categories)
47
49
48
50
| Attack Vector / Category | Specific Vectors Tested | Status |
|**Resource & Process Safety**| Timeout always terminates the child process (no leaked runaway processes); non-positive timeouts rejected |**[PASS] Enforced**|
59
+
|**Error Handling**| Unpicklable results raise a clear `RuntimeError`; child exceptions propagate with their original type; `queue.empty()` race eliminated |**[PASS] Working**|
***Security Hardening**: With `allow_attributes=True`, *all* attribute names starting with `__` are now rejected (previously only a cherry-picked list of dunders). This closes a bypass where dunder attributes could be read through string arguments, e.g. `().__getattribute__('__class__')`.
79
+
***Bug Fix**: A timed-out evaluation now always terminates the child process. Previously `immediate_termination=False` leaked an unkillable, CPU-spinning process. The `immediate_termination` parameter is deprecated and ignored.
80
+
***Bug Fix**: Unpicklable evaluation results (e.g. lambdas, generators, `mappingproxy` objects) now raise a clear `RuntimeError` instead of a misleading `EvaluationTimeoutError`. Results are serialized synchronously inside the child, eliminating the unreliable `queue.empty()` race that could drop valid results.
81
+
***Bug Fix**: `encrypt()` now fails loudly with a clear `ValueError` when the code contains characters outside its supported alphabet. Previously such code — anything non-ASCII — was **silently corrupted** and could not be decrypted. Custom `mapping` values are validated to be exactly 64 characters, as the fixed-size decrypt chunking requires.
82
+
***Bug Fix**: `decrypt()` validates the Base64 input (`validate=True`) and produces clear errors for corrupt input; surrounding whitespace is tolerated.
83
+
***Bug Fix**: Non-positive `timeout` values are rejected with `ValueError`.
84
+
* Exceptions from the evaluation child process now propagate with their original type (including `BaseException`); exception chaining (`raise ... from e`) is used throughout; decrypted code executed via `run()` gets a clean `__main__` namespace isolated from CodeSafe's module globals.
85
+
* Removed `dir()` and `id()` from the default safe builtins (pure information leakage with no legitimate use in expressions).
86
+
* All encryption/decryption file operations now explicitly use UTF-8.
87
+
* Packaging modernized: PEP 621 `pyproject.toml` (SPDX `MIT` license); source distributions and wheels build correctly from a fresh checkout (the `{{VERSION_PLACEHOLDER}}` version made `pip install .` and `python -m build` fail).
88
+
* CI modernized: fixed the broken publish workflow (deprecated `set-output`, unpinned `@master` actions), added a tag-vs-version consistency check, and added a test workflow running both suites on Python 3.8-3.12 across Linux, Windows and macOS.
89
+
* See [SECURITY_AUDIT.md](SECURITY_AUDIT.md) for the full audit findings and remediation notes.
90
+
67
91
### Changelog v0.0.5:
68
92
69
-
***Security Fix**: Patched critical sandbox escape vulnerability in `safe_eval()` (CVE pending), thanks to [@hkmj19](https://github.com/hkmj19)/[Linkedin](https://www.linkedin.com/in/hemanth-kumar-mj-24b50a256/) for reporting.
93
+
***Security Fix**: Patched critical sandbox escape vulnerability in `safe_eval()` (CVE-2026-133467), thanks to [@hkmj19](https://github.com/hkmj19)/[Linkedin](https://www.linkedin.com/in/hemanth-kumar-mj-24b50a256/) for reporting.
70
94
* Blocked indirect function calls via `ast.Subscript`, `ast.Attribute`, and other non-`ast.Name` targets
71
95
* Implemented minimal safe builtins whitelist excluding `exec`, `eval`, `compile`, `__import__`, and similar dangerous functions
72
96
* Added regression tests for indirect call bypass attempts
@@ -105,12 +129,13 @@ pip install codesafe
105
129
106
130
CodeSafe supports the following Python versions:
107
131
108
-
* Python 3.6
109
-
* Python 3.7
110
132
* Python 3.8
111
133
* Python 3.9
112
134
* Python 3.10
113
-
* Python 3.11/Later (Preferred)
135
+
* Python 3.11
136
+
* Python 3.12 (Preferred)
137
+
138
+
Versions 0.0.5 and earlier supported Python 3.6/3.7, but those versions are end-of-life and are no longer supported as of 0.0.6.
114
139
115
140
Please ensure that you have one of these Python versions installed before using CodeSafe. CodeSafe may not work as expected on lower versions of Python than the supported.
116
141
@@ -164,6 +189,9 @@ if __name__ == '__main__':
164
189
> [!NOTE]
165
190
> Attribute inspection is disabled when using `safe_eval`. You can read more about how to use `safe_eval` from [here](https://infinitode-docs.gitbook.io/documentation/package-documentation/codesafe-package-documentation?utm_source=gemini).
166
191
192
+
> [!IMPORTANT]
193
+
> CodeSafe's obfuscation format replaces every character with a fixed 64-character output, so **only characters present in the encryption mapping (printable ASCII + common whitespace) can be encrypted**. Since v0.0.6, `encrypt()` raises a clear `ValueError` for anything else (e.g. non-ASCII strings or comments) instead of silently corrupting the code. Escape non-ASCII characters in string literals (e.g. `"\u2713"`) or remove them from comments before encrypting.
0 commit comments