Skip to content

harden(supply-chain): shell-quote-aware tokeniser for the install-detect gate #140

Closed

Description

@thehoff

Background

Surfaced by Codex + Antigravity peer review of #139 and the followup PR (harden/supply-chain-bypass-followups). Both reviewers flagged that shell_tokens() in `src/hooks/supply_chain_gate.rs` is deliberately naïve about quoting:

Tokenise a shell command into (offset, token) pairs, treating the shell operators &&, ||, ;, |, >, >>, <, << as standalone tokens. This is deliberately simple — it does not honour quoting […]

That choice leaves four bypass / false-positive classes wide open today:

  1. Shell-quote wrapped installs slip past. `sh -c 'npm install pkg'`, `bash -c "pnpm install x"` — the quoted region contains a real install but the regex anchor still fires only on the literal whitespace before the verb inside the quotes, while the outer `sh -c` text bypasses other detection paths.
  2. Command-substitution wrapped installs slip past. `$(npm install pkg)`, backticks. Same root cause: text is data to the outer command, but a real install to the inner shell.
  3. Quoted heads slip past. `'npm' install pkg` — the single quotes around the verb break the regex anchor.
  4. Quoted operators inside flag values cause false negatives. `npm install --description="install & test" lodash` — `shell_tokens()` splits on the literal `&`, so the package-bearing scan terminates early and the install can be misclassified as a bare lockfile install.

Proposal

Replace shell_tokens() with a quote-aware variant that:

  • Honours single quotes, double quotes, and ANSI-C `$'…'` form.
  • Surfaces `sh -c `, `bash -c `, `$(…)`, and backtick payloads as first-class segments that the gate can recurse into (closes #SEC-C2 lineage).
  • Keeps the existing operator-splitting (`&&`, `||`, `;`, `|`) for unquoted regions.
  • Round-trips offset / length so claimed-span dedup still works.

Acceptance criteria

Adversarial tests pin every class above; the existing 30+ supply-chain tests still pass; clippy clean.

Out of scope

Plaintext-data false-positive guard (separate issue) — different design.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions