Skip to content

Release v0.0.6: security hardening, bug fixes, packaging & CI modernization - #4

Merged
johanbeytell1 merged 2 commits into
mainfrom
arena/ac26170c-codesafe
Nov 24, 2026
Merged

johanbeytell1 merged 2 commits into
mainfrom
arena/ac26170c-codesafe

Conversation

@johanbeytell1

Copy link
Copy Markdown
Member

Summary

Audit + hardening release for CodeSafe. Fixes two sandbox/resource-safety bugs in safe_eval(), a silent data-corruption bug in encrypt(), a broken package build, and a broken publish workflow. The previously "CVE pending" advisory is now referenced by its assigned ID: CVE-2026-133467.

Security fixes

  • Dunder-attribute bypass closed (allow_attributes=True): all attribute names starting with __ are now rejected, closing ().__getattribute__('__class__')-style reads that defeated the old hardcoded dunder blocklist.
  • Runaway process leak closed: timed-out evaluations always terminate the child process; immediate_termination=False no longer leaks an unkillable CPU-spinning process (parameter deprecated).
  • Removed dir() and id() from the default safe builtins.

Bug fixes

  • Unpicklable eval results (lambdas, generators, mappingproxy) now raise a clear RuntimeError instead of a misleading EvaluationTimeoutError; results are serialized synchronously in the child, eliminating the unreliable queue.empty() race.
  • encrypt() fails loudly on characters outside its supported alphabet — previously any non-ASCII code was silently corrupted and unrecoverable. Custom mapping values are validated (exactly 64 chars).
  • decrypt() validates Base64 input; whitespace-tolerant; clear errors.
  • Non-positive timeout → ValueError; run() executes with __name__ == '__main__' in an isolated namespace; explicit UTF-8 everywhere; exception chaining; original exception types propagate from child processes.

Packaging & CI

  • New PEP 621 pyproject.toml (SPDX MIT) — pip install . / python -m build now work from a fresh checkout (previously the {{VERSION_PLACEHOLDER}} version made them fail).
  • Publish workflow fixed: deprecated set-output removed, actions updated, tag↔version consistency check added; publish uses pypa/gh-action-pypi-publish@release/v1.
  • New test.yml CI: both test suites on Python 3.8–3.12 (Linux) and 3.12 (Windows/macOS) on every push/PR.

Docs & tests

  • README: CVE-2026-133467 referenced in advisory + changelog (was "CVE pending"), v0.0.6 changelog, Python ≥3.8, test counts (73/73 passing), encryption alphabet limitation documented.
  • New SECURITY_AUDIT.md with full findings, remediations, and residual-risk recommendations.
  • New TestHardeningRegression suite + functional tests; test_security_error_on_unsafe_function can no longer pass silently.

Verification

  • python -m unittest test.py test_poc_vulnerability.py → 73 tests, all passing
  • python -m build → clean sdist + wheel (builds from scratch); pip install from both verified
  • All previously reported PoC vectors (49) still blocked/working, plus the new bypasses

🤖 Generated with Arena Agent Mode

johanbeytell1 and others added 2 commits November 24, 2026 06:25
…zation

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>
…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>
@johanbeytell1
johanbeytell1 merged commit aad6623 into main Nov 24, 2026
7 checks passed
@johanbeytell1
johanbeytell1 deleted the arena/ac26170c-codesafe branch November 24, 2026 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant