> ## Documentation Index
> Fetch the complete documentation index at: https://docs.the40thieves.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# codecalc — post-publication security audit

**Date:** 2026-08-21 · **Auditor:** Claude Opus (in-family adversarial audit +
fuzzing) · **Target:** v0.4.0 and unreleased `main` · **Records:** findings and
disposition only. `AUDIT.md` is the full pre-publication audit narrative and
is not superseded by this document; this is a dated follow-up review, not a
replacement.

***

## Threat model

Same boundary `SECURITY.md` already states, read again from an attacker's
seat rather than a reader's:

**In scope.** A malicious caller, malicious executed code, or adversarial
tool input that:

* escapes the sandbox to run code outside the executor's constraints,
* reads or writes host files outside the session workspace or the 23-entry
  env allowlist,
* reaches the network when `no_net` was requested and believed enforced,
* or — the class this audit spent the most time on — makes the server
  **report a guarantee it did not apply**. A false `unenforced: []` is in
  scope even where no data actually left the machine, because the caller has
  no way to tell the difference from the result alone.

**Out of scope, deliberately.** codecalc is documented as a **single-operator,
local, stdio-only** tool (`SECURITY.md`). This audit did not test multi-tenant
isolation, did not assume a hostile co-tenant sharing the same server process,
and did not treat same-uid resource exhaustion as a finding — both are
already named as out of scope by the project's own threat model, and testing
against a boundary the software never claimed to have would not have produced
an actionable finding.

## Method

Two passes, not one:

1. **Read.** Every surface below, source plus its own docstrings/comments,
   checking each claim a comment or docstring makes against what the code
   actually does — the same discipline `AUDIT.md` and the fuzz
   campaign already established for this repo (a docstring that asserts a
   mitigation is a claim, and claims get checked, not trusted).
2. **Live adversarial probes.** Where a claim was checkable by running code
   through the real sandbox — Rust backend, native binary, `no_net` shim
   loaded — it was run, not reasoned about. **E-1** traces to exactly such a
   probe: a `no_net` result that returned a different answer than the
   `unenforced` field beside it promised. **N-2** was found the other way, by
   reading — a write-path docstring that contradicted the read-path one — and
   its parent-directory TOCTOU residual is accepted from the code's structure
   (final-component `O_NOFOLLOW` only), not demonstrated by a live exploit.

This was **not** a cross-vendor review. A Codex pass was attempted and
declined by Codex's own cybersecurity content filter before it could examine
the sandbox code at all — the request itself (executing untrusted code,
bypassing a network block) reads as the thing the filter exists to catch, so
this repo cannot currently get a Codex second opinion on its own security
surface. See **Residuals** below; that gap is an owner action, not something
this audit could route around from inside a single vendor's models.

## Surfaces reviewed

Six, chosen as the boundaries between a caller/executed-code and something
that matters if crossed:

1. **Parse screen** (`safe_expr.py`, `logic.py`, `linalg.py`) — the denylist
   between a caller's expression string and SymPy's `parse_expr`.
2. **Session jail** (`sessions.py`) — path confinement, symlink handling,
   quotas, and workspace cleanup for stateful sessions.
3. **Executor** (`executor.py`, `executor/src/*.rs`) — env allowlist,
   rlimits, process-group kill, `no_net`, and result-shape parity between the
   Rust and Python-fallback backends.
4. **Packages** (`packages.py`) — `install_package`'s argv construction and
   fail-closed behaviour when a manager cannot be confined.
5. **HTTP transport** (`server.py`, `mcp_middleware.py`) — DNS-rebinding
   protection, token auth, and the request/response size guard on
   `serve-http`.
6. **Info leaks** (`errors.py`, `audit.py`, pydantic validation) — whether an
   error path, an audit log entry, or a validation failure echoes something
   it should not (a raw argument value, a host path, a secret).

## Findings

| ID | Severity | Finding | Disposition |
| - | - | - | - |
| **E-1** | Important | `no_net` over-reports enforcement on the Rust backend: the `LD_PRELOAD`/`DYLD_INSERT_LIBRARIES` symbol shim blocks `socket.socket(AF_INET)` as documented, but `ctypes.CDLL(find_library("c")).socket(2, 1, 0)` — resolving `socket()` via `dlsym` on a specific handle rather than through the shimmed global symbol — returns a working fd with the shim loaded, and the result's `unenforced` still read `[]`. | **Fixed** (this change), and since strengthened. `executor.py` now appends a best-effort disclosure to `unenforced` whenever `no_net` was requested and satisfied by the shim. See `CHANGELOG.md` `[Unreleased]` → Security. **Update 2026-08-21 (later same day):** on Linux the disclosure is no longer the whole story — the executor installs a seccomp-bpf filter that refuses the `socket(AF_INET/AF_INET6)` syscall in-kernel, closing the `ctypes`/raw-syscall bypass this row identified rather than only disclosing it. `unenforced=[]` on Linux now means genuinely enforced; the shim (and its disclosed gap) remains the mechanism on macOS and as the Linux fallback when the kernel refuses a seccomp filter. |
| **N-1** | Minor | `safe_expr.safe_global_dict()` — the SymPy namespace `parse_expr` evaluates into — is documented as "defence in depth only… not load-bearing," which is accurate today (`reject_unsafe`/`classify_unsafe` are what actually hold the line, per CRITICAL-01's own lesson: a narrowed namespace is not an evaluator). Flagged because a namespace-based mitigation is the shape of a *future* fragility if a later change ever leans on it as more than that. | **Holds.** No live bypass found; not fixed here. Worth a comment reinforcing "do not treat this as load-bearing" the next time this file changes, tracked as hardening rather than a defect. |
| **N-2** | Minor | `sessions._write_nofollow`'s docstring implied the Landlock confinement covers the parent-directory TOCTOU window ("which is why the Landlock confinement above matters even for a path this function guards"). It does not: Landlock confines the long-lived **worker** process that runs a session's own code (`_session_unenforced`); `write_file`/`read_file`/`resource_read` run in the **server** process, which Landlock never touches. `_read_nofollow`'s own docstring already stated this correctly for the read path — the write-path docstring was the one that overclaimed. | **Fixed** (this change). Docstring-only; no behaviour change. The residual — a session's own code winning a race against the server between `_jail`'s `resolve()` and this function's `open()` to plant a symlink in a *parent* component — is accepted pending `openat2(RESOLVE_BENEATH)` (Linux 5.6+, no portable equivalent), same as it was before this fix; only the stated reason for accepting it changed. |
| **N-3** | Minor | Installer/setup scripts print host filesystem paths to stderr on some failure branches (e.g. where a runtime or package manager could not be found). Not a leak across a trust boundary for the deployment this project documents. | **Benign for single-operator use.** codecalc's stderr already carries operator-facing diagnostics by design; a local path in a local error to the local operator who is the only reader is not the class of leak `SECURITY.md`'s threat model is about. No fix filed. |

## What held

Per surface, what was probed and did not break:

* **Parse screen.** No RCE reachable through `safe_expr`/`logic.truth_table`/
  SymPy `parse_expr` in this pass — CRITICAL-01's dunder-chain class stays
  closed (`tests/test_security.py` still asserts it live). `safe_global_dict()`
  has no Python builtins in it, verified by inspection and by probing for an
  evaluator reachable through the exposed SymPy namespace; none was found.
  Cost bounds (`MAX_SYMBOLIC_EXPONENT`, `MAX_NUMERIC_DIGITS`, the variable-count
  and expression-length caps) fired on the inputs built to trip them.
* **Session jail.** No escape found: the component-wise `is_relative_to`
  boundary check held against sibling-directory and
  symlink probes; `_jail`'s length/segment caps held against the fuzz-shaped
  DoS inputs surfaced; quota accounting and workspace cleanup
  (`_rmtree_checked`, identity-checked against a swapped directory) held.
* **Executor.** Env-drop (the 23-entry allowlist), rlimits (CPU/memory/output/
  process-count), process-group kill on timeout, and workdir-identity cleanup
  all held under adversarial probes — **except** `no_net`, which is E-1
  above. Every other ceiling that claims enforcement on this platform
  (`test_platform_contract.py`'s "anything NOT reported unenforced must
  actually bite" half) still bites.
* **Packages.** `install_package` still passes package strings as argv only,
  never through a shell, and still fails closed rather than silently
  degrading when a manager cannot be confined (Landlock unavailable, or a
  platform with no equivalent).
* **HTTP.** DNS-rebinding protection (loopback allowlist vs. a spoofed Host
  header), token auth, and the request/response size guard on `serve-http`
  all held against the probes built against them.
* **Info leaks.** pydantic validation errors no longer echo a caller's raw
  argument value (#212b) and still hold; audit-log entries and error
  paths probed for this audit did not surface a host path, secret, or
  argument value that the existing redaction should have caught.

## Residuals for the owner

Nothing here is new — each is already named in `SECURITY.md` or `AUDIT.md`'s
own residual-risk sections — restated because this audit specifically
re-checked each one rather than assuming it still held:

1. **No true network isolation without a container/microVM.** `no_net`
   (post-E-1) now says so honestly; it was never meant to be more than a
   speed bump. Real isolation is `--network=none` or gVisor/Firecracker, not
   a symbol shim, on any platform. **Update 2026-08-21:** narrower than
   stated above for Linux specifically — a seccomp-bpf filter now enforces
   `no_net` there in-kernel (the socket syscall itself is refused, not just
   the symbol), so this residual is now a macOS/no-seccomp-fallback
   statement rather than a universal one. The container/microVM caveat still
   holds everywhere for isolation beyond `no_net` alone (filesystem, other
   same-uid processes, etc.).
2. **Same-uid execution.** rlimits constrain, they do not sandbox a hostile
   program away from other files this user can read. Full isolation needs
   containers or a VM — out of scope for the tool as documented, in scope the
   moment anyone points it at multi-tenant or internet-facing traffic.
3. **No independent third-party review.** This audit and its fuzzing-campaign
   predecessor are both Claude-family (in-house). The attempted cross-vendor
   Codex pass was blocked by Codex's own content filter before it could
   examine sandbox code at all (see Method) — a genuinely independent
   security review (a firm, or an external maintainer with no relationship to
   this codebase's own model family) has not happened and remains an owner
   action, not something addressable from inside this audit.
4. **No external maintainer.** Single-maintainer project (`SECURITY.md`
   already says so for response-time expectations); a second set of eyes with
   commit access and no stake in any given PR would catch a different class
   of thing than either this audit or a fuzz campaign can.

## What this document is not

Not a certification, not a warranty, and not independent of the codebase it
reviews — an in-family model auditing a project whose threat model centers on
"a model executes code here" carries the same limitation `AUDIT.md` already
names for its own author. Weigh it accordingly, same instruction
`SECURITY.md` gives for `AUDIT.md` itself.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.