Repository navigation
fix: OWASP agentic hardening — fenced tool results, env scrubbing, destructive-argv gate, job log cap - #75
Merged
Merged
Conversation
…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") |
🔍 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.TOOL_RESULTmarkers; forged markers in content neutralized from the inside (ZWSP breaks the sequence).scrub_env_for_childapplied at every spawn point — secret-shaped env names never reach children (GITHUB_TOKENkept for auth, documented).check_destructive_argvgate 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 likenohup sh -c, env with assignments/-u/-C, busybox, xargs) scanned recursively/conservatively.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)
cat middleware.ts,which rm, scopedrm -rf ./build, env assignments).Closes #72 (structural follow-ups noted in the threat model: per-call Destructive classification design; MCP re-opens the trust model).