Skip to content

[Maintenance] Implement rm-rf-with-unresolved-variables detection (#1004 honest gap) #1008

@akaszubski

Description

@akaszubski

Problem

Issue #1004 fixed the hard-floor registry function name mismatch. During that work, the security-auditor surfaced an honest gap: the aspirational rm -rf with unresolved variables semantic was listed in hard_floor_hooks.json registry as a protected pattern, but no implementation exists anywhere that detects this specific class of dangerous commands.

The hard-floor registry now honestly reflects reality (post-#1004), but the gap itself remains open: a rm -rf $UNSET_VAR command passes through the hook layer unchallenged.

Evidence

From issue #1004's security-auditor output:

"1 LOW pre-existing rm-rf-vars semantic gap — the aspirational 'rm -rf with unresolved variables' detection is NOT implemented anywhere. Registry now honestly reflects this."

The hard_floor.py likely contains a _check_dangerous_bash() stub or similar placeholder that was never implemented.

Suggested Fix

Option A — Implement the detection (preferred):

  • In plugins/autonomous-dev/lib/hard_floor.py, add a function _check_rm_rf_unresolved_vars(command: str) -> bool that detects patterns like:
    • rm -rf $VARNAME where $VARNAME is not quoted
    • rm -rf ${VARNAME} with potentially empty expansion
    • rm -rf "$VARNAME" is SAFE (quoted, empty → removes nothing at that path)
  • Use regex: r'rm\s+-rf?\s+\$\{?[A-Z_][A-Z0-9_]*\}?(?!\s*["\'])' as a starting point
  • Add unit tests in tests/unit/lib/test_hard_floor.py
  • Update registry entry with implemented: true

Option B — Accept the gap formally:

  • Add a KNOWN-GAPS.md doc entry explaining why this detection is out of scope (e.g., requires shell expansion context that's unavailable at hook time)
  • Remove or mark the registry entry as aspirational: true with an explicit rationale

Why This Matters

The rm-rf-vars class of bugs is a high-impact footgun in automation scripts. If the pipeline ever passes an unset variable through a bash command (e.g., from a failed env lookup), the result could be catastrophic directory deletion. Hook-level detection at HARD GATE priority is the correct defense layer.

Context

Plugin Version: 3.50.0 (995ee2d)


Filed automatically by continuous-improvement-analyst

Metadata

Metadata

Assignees

No one assigned

    Labels

    auto-improvementContinuous improvement analyst findings

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions