Skip to content

Phase D: Harden Shell and Backup Enforcement #222

Description

@Cho-Geer

Description

Block script payload staging (e.g., cat > /tmp/impl.ts with workspace writes) and unify shell write classification. Ensure all framework file modifications go through backup-aware tools.

Code References (§6 Phase D)

Files to Modify

  • .opencode/lib/tool-scope.ts
  • .opencode/lib/safe-bash-core.ts
  • .opencode/plugins/scope-before.ts
  • .opencode/lib/backup-manager.ts
  • .opencode/lib/__tests__/safe-bash-core.test.ts

Changes

  1. Add shared shell write classifier — return read_only, known_write, opaque_write, or script_payload_write.

  2. Heredoc/stdin inspection — for cat > / <<EOF redirections, capture or inspect payload before allowing. If content contains writes to workspace paths, block at payload creation time.

  3. Temp script scanning — for /tmp/*.ts, /tmp/*.js, /tmp/*.py, /tmp/*.sh, scan content and target writes before execution. Extend script scanning from node *.ts/*.js to bun, python3, bash, sh, tsx, and /tmp/*.

  4. Block payload creation if it stages writes to workspace files (.opencode/**, booking-backend/**, booking-frontend/**).

  5. Remove path-aware eval allowance for framework writes — only .task_temp/_logs diagnostics can be written by shell. Remove // safe_bash: allow-write bypass; convert to "must use backup-aware repair wrapper."

  6. Add backup_uuid requirement — before any framework file write, verify a backup_log row exists or create one atomically. Record backup_uuid on write audit events.

  7. Remove broad "trusted script path" bypasses unless script is signed by config and declared in a DB-backed allowlist.

Acceptance Criteria

  • cat > /tmp/impl.ts <<EOF with writeFileSync(".opencode/...") is blocked at creation
  • bun /tmp/impl.ts is blocked even if creation happened before the fix
  • python3 <<EOF open(".opencode/...","w") is blocked
  • safe_edit still succeeds and creates a backup_log row
  • Today's log evidence (scope-before-runtime.log:4214, 4481) of payload staging is prevented

Testing

bun test .opencode/lib/__tests__/safe-bash-core.test.ts

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingenhancementNew feature or requesttesting

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions