Skip to content

Commit dc2d23e

Browse files
Use authenticated crypto for encryption, drop restricted_imports, TP release flow
Encryption (breaking change, documented): - encrypt() now uses Fernet (AES-128-CBC + HMAC-SHA256) with a 256-bit key; any Unicode source round-trips losslessly (plaintext is UTF-8) - New generate_key() helper; keys resolve via key= > CODESAFE_KEY env > built-in default (public, obfuscation-grade, documented) - Files written by encrypt_to_file() are self-describing: # codesafe:v2:<token> - Legacy pre-0.0.6 Base64 Caesar payloads remain fully decryptable/runnable via decrypt()/decrypt_to_file()/run(); legacy mapping still honored there - encrypt() no longer accepts the Caesar mapping parameter (TypeError) safe_eval: - Restricted imports parameter removed (redundant with the blanket import ban) - Results are serialized with cloudpickle: lambdas and dynamically created classes can now be returned; generators/modules still raise a clear RuntimeError (instead of the old misleading EvaluationTimeoutError) CI/release: - Tests run on 3.8/3.9 via ubuntu-22.04 (not available on ubuntu-latest/24.04, which is why those jobs failed at setup); deps installed directly - Publish workflow uses PyPI Trusted Publishing (OIDC, id-token: write); no stored API tokens; distributions carry PEP 740 provenance attestations - README gains a provenance badge linked to the PyPI security tab Docs: - New SECURITY.md (private reporting instructions, supported versions, published advisories) - SECURITY_AUDIT.md dropped; its content now lives in the README (Security Advisory + Security Limitations & Notes sections) - v0.0.5 changelog now carries a prominent warning about the second, known sandbox-escape issue (allow_attributes=True, fixed in 0.0.6) - _ = backwards-compatible positional legacy mapping for decrypt-time calls Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
1 parent 3ba2bb1 commit dc2d23e

10 files changed

Lines changed: 470 additions & 305 deletions

File tree

‎.github/workflows/build_and_publish.yml‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ jobs:
99
build-n-publish:
1010
name: Build and publish Python 🐍 distributions 📦 to PyPI
1111
runs-on: ubuntu-latest
12+
13+
# Required for PyPI Trusted Publishing (OIDC). No API token or
14+
# password is stored in this repository. The token is minted on
15+
# demand by GitHub and verified by PyPI against the trusted
16+
# publisher configuration for this project.
17+
permissions:
18+
id-token: write
19+
1220
steps:
1321
- uses: actions/checkout@v4
1422

@@ -34,7 +42,8 @@ jobs:
3442
- name: Build a binary wheel and source distribution
3543
run: python -m build
3644

45+
# Publishes via PyPI Trusted Publishing (OIDC). The distribution
46+
# is attested (PEP 740) and the provenance is shown on PyPI under
47+
# the "Provenance" information for the release files.
3748
- name: Publish distribution 📦 to PyPI
3849
uses: pypa/gh-action-pypi-publish@release/v1
39-
with:
40-
password: ${{ secrets.PYPI_API_TOKEN }}

‎.github/workflows/test.yml‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
os: [ubuntu-latest]
16-
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
16+
python-version: ['3.10', '3.11', '3.12']
1717
include:
18+
# Python 3.8/3.9 are not available in the ubuntu-latest (24.04)
19+
# toolcache, so they run on ubuntu-22.04 instead.
20+
- os: ubuntu-22.04
21+
python-version: '3.8'
22+
- os: ubuntu-22.04
23+
python-version: '3.9'
1824
- os: windows-latest
1925
python-version: '3.12'
2026
- os: macos-latest
@@ -28,5 +34,13 @@ jobs:
2834
with:
2935
python-version: ${{ matrix.python-version }}
3036

37+
- name: Install dependencies
38+
# The test suite imports codesafe from the repository root, so the
39+
# package itself does not need to be built; only its runtime
40+
# dependencies are required.
41+
run: |
42+
python -m pip install --upgrade pip
43+
python -m pip install "cryptography>=41" "cloudpickle>=2.2"
44+
3145
- name: Run test suite
3246
run: python -m unittest test.py test_poc_vulnerability.py -v

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ encrypted_code.encrypt
1414
decrypted.py
1515
codesafe_rce_marker.txt
1616
pathlib_test.txt
17+
v2_test_prog.encrypt

‎README.md‎

Lines changed: 69 additions & 21 deletions
Large diffs are not rendered by default.

‎SECURITY.md‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Security Policy
2+
3+
We take the security of CodeSafe seriously. Thank you for helping keep CodeSafe and its users safe.
4+
5+
## Reporting a vulnerability
6+
7+
**Please do not report security vulnerabilities through public GitHub issues, discussions, or pull requests.**
8+
9+
Instead, please report them privately using one of the following channels:
10+
11+
1. **GitHub private vulnerability reporting (preferred):** open the [Security tab](https://github.com/Infinitode/CodeSafe/security) of this repository and choose **Report a vulnerability** (or go directly to https://github.com/Infinitode/CodeSafe/security/advisories/new). This creates a private advisory visible only to the maintainers, and allows us to collaborate on the fix and publish a coordinated disclosure.
12+
2. **Email:** [infinitode.ltd@gmail.com](mailto:infinitode.ltd@gmail.com) with a subject line starting with `[SECURITY] CodeSafe`.
13+
14+
Please include as much of the following as you can:
15+
16+
- The package version(s) affected
17+
- A description of the vulnerability and its impact
18+
- Steps to reproduce / a proof of concept
19+
- The environment (OS, Python version)
20+
- Any suggested mitigations or fixes (optional)
21+
22+
## What to expect
23+
24+
- We aim to acknowledge your report within **7 days** (best effort; this is a small open-source project).
25+
- We will assess the report, determine the severity (CVSS) and the affected version range, and keep you informed of progress.
26+
- We will develop the fix privately, prepare a draft GitHub Security Advisory, and publish the advisory, the fix (a new release) and (if applicable) request a CVE ID when the release is out — following coordinated disclosure.
27+
- With your permission, we will credit you in the advisory and changelog. If you prefer to remain anonymous, just say so.
28+
29+
We ask that you give us reasonable time to release a fix before any public disclosure.
30+
31+
## Supported versions
32+
33+
| Version | Supported |
34+
| :--- | :--- |
35+
| 0.0.6 and later | ✅ Yes |
36+
| 0.0.5 | ⚠️ Known issue — see [Security Advisory](README.md#security-advisory); upgrade to 0.0.6 |
37+
| 0.0.1 – 0.0.4 | ❌ No — critical sandbox escape, [CVE-2026-133467](https://github.com/Infinitode/CodeSafe/security/advisories/GHSA-7gp8-3j6q-v4h8) |
38+
39+
Only the latest release receives fixes. Please upgrade rather than report issues that may already be fixed.
40+
41+
## Published advisories
42+
43+
| Advisory | CVE / GHSA | Affected | Fixed in |
44+
| :--- | :--- | :--- | :--- |
45+
| `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 |
46+
| `safe_eval` sandbox escape via dunder attribute string-argument (`allow_attributes=True`) | Pending assignment (draft advisory) | 0.0.3 - 0.0.5 | 0.0.6 |
47+
48+
See https://github.com/Infinitode/CodeSafe/security/advisories for the canonical list.
49+
50+
## Scope notes
51+
52+
CodeSafe contains two very different components, and reports are welcome for both, but keep in mind:
53+
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.
55+
- **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.
56+
57+
Thank you for helping make CodeSafe safer!

‎SECURITY_AUDIT.md‎

Lines changed: 0 additions & 116 deletions
This file was deleted.

0 commit comments

Comments
 (0)