Skip to content

security(wasm): bound sandbox resources, remove host panic/DoS vectors#93

Merged
ndreno merged 1 commit into
mainfrom
security/wasm-sandbox-limits
Jun 30, 2026
Merged

security(wasm): bound sandbox resources, remove host panic/DoS vectors#93
ndreno merged 1 commit into
mainfrom
security/wasm-sandbox-limits

Conversation

@ndreno

@ndreno ndreno commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Area: WASM sandbox limits

Hardens the WASM host runtime against a hostile or compromised plugin. Fail-closed by default, with operator opt-outs where appropriate. Continues the sequential, one-PR-per-area security work.

Panic vectors removed

  • Guest-controlled pointer/length slice reads in instance.rs use saturating_add, so a negative/oversized len fails the existing bounds check instead of panicking on an inverted range.
  • cache.rs / rate_limiter.rs Instant/Duration arithmetic is overflow/underflow-safe (checked_* / saturating_* / duration_since), including cleanup paths that underflow in the first minutes of process uptime.

Memory bounds (DoS)

  • Response cache caps its entry count (evicts expired, then soonest-to-expire).
  • Rate limiter clamps plugin-supplied quota and window, and caps the partition table — failing closed when saturated with active keys.

Upstream body cap

  • The buffered plugin HTTP-call path reads at most BARBACANE_MAX_UPSTREAM_RESPONSE_BYTES (default 16 MiB) via a chunked, Content-Length-aware read. Streaming dispatchers are unaffected.

Wall-clock backstop

  • Epoch interruption + a background ticker trap a guest that runs past its time budget, complementing fuel-based CPU limiting.

Broker hardening (Kafka/NATS)

  • SSRF guard on broker addresses (honors BARBACANE_ALLOW_INTERNAL_EGRESS), connect/publish timeouts, bounded connection caches.
  • Runtime build errors now propagate instead of expect-panicking.

Docs

  • BARBACANE_MAX_UPSTREAM_RESPONSE_BYTES documented; internal-egress default note extended to brokers; CHANGELOG updated.

Verification

  • cargo fmt --all --check, cargo clippy --workspace --lib --bins --exclude barbacane-test -D warnings, and cargo test --workspace --lib --bins --exclude barbacane-test all green. New unit tests cover the body cap, cache/quota/window clamps, broker SSRF rejection, and split_host_port.

Resolves the WASM sandbox-limits items tracked privately (#3/#4).

…S vectors

Hardens the WASM host runtime against a hostile or compromised plugin
(area: WASM sandbox limits).

- Panic vectors: guest-controlled pointer/length slice reads use
  saturating_add so a negative/oversized len fails the existing bounds
  check instead of panicking on an inverted range. Cache and rate-limiter
  Instant/Duration arithmetic is overflow/underflow-safe (checked/
  saturating + duration_since), including the cleanup paths that
  underflow early in process uptime.
- Memory bounds: the response cache caps its entry count (evicting
  expired-then-soonest-to-expire); the rate limiter clamps the
  plugin-supplied quota and window and caps the partition table, failing
  closed when saturated with active keys.
- Upstream body cap: the buffered plugin HTTP-call path reads at most
  BARBACANE_MAX_UPSTREAM_RESPONSE_BYTES (default 16 MiB) via a chunked,
  content-length-aware read, bounding host memory.
- Wall-clock backstop: epoch interruption with a background ticker traps
  a guest that runs past its time budget, complementing fuel-based CPU
  limiting.
- Broker hardening: Kafka/NATS connections enforce the SSRF guard
  (honoring BARBACANE_ALLOW_INTERNAL_EGRESS), connect/publish timeouts,
  and bounded connection caches. Runtime build errors propagate instead
  of panicking.

Docs and CHANGELOG updated for the new env var and broker egress default.
@ndreno ndreno merged commit d19349f into main Jun 30, 2026
12 checks passed
@ndreno ndreno deleted the security/wasm-sandbox-limits branch June 30, 2026 12:47
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