Skip to content

fix: OWASP agentic hardening — fenced tool results, env scrubbing, destructive-argv gate, job log cap - #75

Merged
ajianaz merged 2 commits into
developfrom
fix/owasp-hardening-72
Sep 12, 2026
Merged

ajianaz merged 2 commits into
developfrom
fix/owasp-hardening-72

Conversation

@ajianaz

@ajianaz ajianaz commented Sep 12, 2026

Copy link
Copy Markdown
Contributor

What (description of the change)

Issue #72 deliverables:

  • docs/threat-model.md: full OWASP Agentic/LLM Top-10 mapping (control / gap / N-A with rationale), assets, trust boundaries, deliberate limitations.
  • Fence: tool results on the provider wire wrapped in TOOL_RESULT markers; forged markers in content neutralized from the inside (ZWSP breaks the sequence).
  • ENV-1: scrub_env_for_child applied at every spawn point — secret-shaped env names never reach children (GITHUB_TOKEN kept for auth, documented).
  • RC-1: shared check_destructive_argv gate on run_command AND job_start: path-qualified programs, teardown tools (dd/mkfs/shutdown/init/fdisk...), recursive rm with workspace-escaping targets refused; wrapper payloads (sh/bash -c incl. combined flags, nested wrappers like nohup sh -c, env with assignments/-u/-C, busybox, xargs) scanned recursively/conservatively.
  • JOB-2: job logs in append mode (no NUL holes), poll-side truncation via bounded window (no multi-GiB allocation), job dirs 0700.

Why (the problem you're solving)

Fixes so far were finding-driven; #72 demanded a threat-model-driven audit. The audit surfaced four cheap-to-close gaps: workspace files could forge the tool-result data boundary (prompt injection), children inherited every host secret, the Write tier was bypassable by catastrophic argv (also reachable from job_start), and an unpolled chatty job could grow disk/memory without bound.

Testing (how you verified this works)

  • 24 destructive-argv scanner cases (16 refused: direct/flag-cluster/path-qualified/wrapper/nested-shell/compound-payload bypasses; 12 benign pass: cat middleware.ts, which rm, scoped rm -rf ./build, env assignments).
  • Fence unit test (wrap + forged-marker neutralization), env-scrub test through a real child process env, log-cap test with a >10 MiB log.
  • Full workspace suite green, mobile profile green, fmt + clippy -D warnings clean.
  • CodeCora review loop on this diff: 5 rounds, 12 majors raised — ALL real (race panic, NUL holes, substring over-match, wrapper/payload bypasses, env-assignment bypass, underflow, OOM window, missing job_start gate) — ALL fixed before it came clean.

Closes #72 (structural follow-ups noted in the threat model: per-call Destructive classification design; MCP re-opens the trust model).

…structive-argv gate, job log cap (issue #72)

Threat model (docs/threat-model.md) maps tole against the OWASP
Agentic/LLM Top 10; every item resolved to control/gap/N-A with
rationale. Four quick-win gaps closed in the same change:

- Fence: tool results on the wire are wrapped in TOOL_RESULT markers
  with forged markers neutralized from the inside (ZWSP), so workspace
  data cannot forge the data boundary (prompt-injection mitigation).
- ENV-1: children of every spawn point (run_command, job_start, git,
  gh, cora, uteke) inherit a scrubbed env — secret-shaped names
  (API_KEY/_SECRET/_TOKEN/PASSWORD) removed; GITHUB_TOKEN kept for
  auth, documented as a deliberate limitation.
- RC-1: destructive argv gate applied to run_command AND job_start via
  a shared check_destructive_argv scanner — path-qualified programs,
  teardown tools (dd/mkfs/shutdown/...), and recursive rm escaping the
  workspace are refused; wrapper payloads (sh/bash -c incl. combined
  flags and nested wrappers, env with assignments/-u/-C, busybox,
  xargs, nohup) are recursed/scanned conservatively. Token-level
  matching keeps benign commands (cat middleware.ts, which rm) working.
- JOB-2: job logs append-mode (no sparse NUL holes), truncated at poll
  to a bounded window (no unbounded memory/disk growth), jobs dirs
  0700.

Verification: 24 scanner unit cases (16 refused incl. wrapper/nested
bypasses, 12 benign), fence unit test, env-scrub integration-style
test via child env, log-cap test; full workspace + mobile profile
green; clippy -D warnings clean. CodeCora review loop on this diff ran
5 rounds (12 majors raised, all real, all fixed) before coming clean.
// sh/bash command-string mode: any -c inside a short-flag
// cluster selects the payload; scan EVERY non-flag argument
// conservatively (compound commands, trailing args).
if (prog == "sh" || prog == "bash")
@github-actions

github-actions Bot commented Sep 12, 2026 •

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

…a round 6)

CodeCora flagged sudo/timeout/find/python bypasses. sudo/doas are
cheap to wrap (added, tested). The rest are accepted residual risk of
a best-effort blocklist: the doc comment now says so explicitly, and
threat-model.md RC-1 row no longer claims a full fix — primary control
is the approval gate, argv sandboxing is a different product.
@ajianaz
ajianaz merged commit 027e83c into develop Sep 12, 2026
13 checks passed
@ajianaz
ajianaz deleted the fix/owasp-hardening-72 branch September 12, 2026 11:07
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.

Security: OWASP Agentic/LLM checklist audit + gap fixes

2 participants