Skip to content

CP-2: Phase 1 Quick Wins — Wasmtime hardening, deny(unsafe_code), sandwich framing, bounds checking, sanitized errors#4

Merged
modpunk merged 2 commits intomainfrom
cp-2-phase1-quick-wins
Mar 23, 2026
Merged

CP-2: Phase 1 Quick Wins — Wasmtime hardening, deny(unsafe_code), sandwich framing, bounds checking, sanitized errors#4
modpunk merged 2 commits intomainfrom
cp-2-phase1-quick-wins

Conversation

@modpunk
Copy link
Copy Markdown
Owner

@modpunk modpunk commented Mar 23, 2026

Phase 1 Quick Wins (Ralph Architecture)

Changes

Ralph Layer 14 — Hardened Wasmtime config (sandbox.rs)

  • Disabled 8 unnecessary WASM features: threads, SIMD, multi-memory, bulk memory, reference types, tail calls, component model, GC

Ralph Layer 6 — Sandwich prompt framing (prompt_builder.rs)

  • Added SECURITY_BOUNDARY as final system prompt section
  • Reasserts trust boundary against prompt injection from user content and tool results

Ralph Layer 30 — Sanitized error responses (sanitized_errors.rs)

  • New module: generic user-facing errors with correlation IDs
  • Full details logged to audit trail only

WASM boundary hardening (sandbox.rs)

  • Input/output size enforcement (4 MB max)
  • 64-bit safe casts via try_into() — eliminates silent truncation
  • Checked arithmetic on all pointer+length operations
  • Negative pointer rejection
  • Log message size cap (8 KB)

deny(unsafe_code) on 10 crates

  • channels, desktop, extensions, hands, memory, migrate, runtime, skills, types, wire

Files modified

  • crates/openfang-runtime/src/sandbox.rs — Wasmtime config + bounds hardening
  • crates/openfang-runtime/src/prompt_builder.rs — Sandwich framing
  • crates/openfang-api/src/sanitized_errors.rs — NEW: error sanitization module
  • crates/openfang-api/src/lib.rs — Wire in sanitized_errors
  • 10 x lib.rs — deny(unsafe_code)

Not in this PR (deferred)

  • Seccomp-bpf (needs Linux-specific testing)
  • Systematic routes.rs error migration (pattern established, needs file-wide sweep)
  • StoreLimiter for WASM memory enforcement
  • Zeroizing gaps in driver mod.rs

modpunk added 2 commits March 23, 2026 03:52
…raming, sanitized errors

Ralph Layer 14 — Hardened Wasmtime config:
  Disabled wasm_threads, wasm_simd, wasm_multi_memory, wasm_bulk_memory,
  wasm_reference_types, wasm_tail_call, wasm_component_model, wasm_gc
  in sandbox.rs Engine config. Reduces attack surface and CVE exposure.

Ralph Layer 6 — Sandwich prompt framing:
  Added SECURITY_BOUNDARY constant as final section of system prompt.
  Reasserts trust boundary so LLM has security context fresh in working
  memory when processing user messages and tool results.

Ralph Layer 30 — Sanitized error responses:
  New sanitized_errors.rs module with correlation-ID-based error logging.
  Generic user-facing messages, full details in audit trail only.
  Wired into openfang-api, ready for systematic routes.rs migration.

deny(unsafe_code) on 10 crates:
  channels, desktop, extensions, hands, memory, migrate, runtime,
  skills, types, wire. 3 crates with existing unsafe (api, cli, kernel)
  left without deny for now.
…ze limits

sandbox.rs execute_sync:
  - Input size enforcement (4 MB max)
  - 64-bit safe cast via try_into() instead of 'as i32' truncation
  - Checked addition for pointer + length (no overflow)
  - Negative pointer rejection

sandbox.rs host_call:
  - Negative pointer/length rejection
  - Checked addition for request bounds
  - Safe cast for response length (try_into instead of 'as i32')
  - Checked addition for response write bounds

sandbox.rs host_log:
  - Negative pointer/length rejection
  - Checked addition for bounds
  - Log message size cap (8 KB) to prevent log flooding from guest
@modpunk modpunk merged commit 4bb7f62 into main Mar 23, 2026
6 of 11 checks passed
@modpunk modpunk deleted the cp-2-phase1-quick-wins branch March 23, 2026 04:20
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