Skip to content

fix(memory): harden cross-device sync transport (git option injection + env leak) - #188

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

What

Track C — adversarial hardening of the 3.0 memory-sync surface (src/memory/remote-sync.ts). Two findings, both fixed here.

MEDIUM — git option injection on the remote/branch

remote/branch from ~/.kit/sync.toml reach git as positional argv via execFileSync (no shell, so OS metacharacters are already inert), but two git-level vectors remained:

  • a value starting with - is parsed as an option — a remote of --upload-pack=<cmd> turns git clone into arbitrary command execution;
  • ext::/fd:: remote helpers run commands by design (git clone ext::sh -c …).

Fix:

  • loadSyncConfig rejects a remote/branch starting with -, and an ext::/fd:: remote;
  • cloneOrInit passes --end-of-options before the positional operands;
  • the git() helper runs with protocol.ext.allow=never protocol.fd.allow=never.

Config is operator-owned (read only from ~/.kit/sync.toml, never the repo tree), so realistic severity is bounded — this is defense-in-depth, and it future-proofs any sync init that ingests a remote from a less-trusted source.

LOW — kit secrets leaked into the transport command's environment

runTransportCmd handed the entire process.env (including KIT_MEMORY_PASSPHRASE) to the operator's push_cmd/pull_cmd. That command only ever moves the already-encrypted blob, so it never needs the passphrase — and a transport that logs its environment (aws --debug, a set -x shell, an error tracer) would spill the passphrase right next to the ciphertext it protects, collapsing the encryption guarantee.

Fix: the child env is stripped of every kit-managed *(PASSPHRASE|SECRET|TOKEN|PASSWORD|KEY) var; the operator's own provider credentials (AWS_*, etc.) still pass through, and KIT_MEMORY_BLOB is still provided.

Tests

2 new tests: loadSyncConfig rejects an option-injecting remote/branch and ext:: helpers (and still loads a normal config); the transport = "command" child env never contains KIT_MEMORY_PASSPHRASE (or its value) while still receiving KIT_MEMORY_BLOB. Full suite 1981 green, prettier clean.

Context

Final PR of the A→B→C hardening arc: #185 (docs) → #186 (external timestamp anchor) → #187 (PAL device-fence + device identity) → this (transport hardening). All findings came from an adversarial review of the new 3.0 surface; the memory content path itself was confirmed clean (travels as a GCM blob by path, verify_cmd demoted on merge, path-traversal guarded).

🤖 Generated with Claude Code

https://claude.ai/code/session_015ERHw6bVUz39sAuoQZ1iyg


Generated by Claude Code

… + env leak)

Track C adversarial hardening of the 3.0 memory-sync surface.

MEDIUM — git option injection. The remote/branch from ~/.kit/sync.toml reach git
as positional argv (no shell), but a '-'-leading value is parsed as an option
(remote = "--upload-pack=<cmd>" → RCE on clone) and ext::/fd:: remote helpers run
commands by design. loadSyncConfig now rejects both; cloneOrInit passes
--end-of-options before the positional operands; git() runs with
protocol.ext/protocol.fd disabled. Config is operator-owned (low realistic
severity) but this is defense-in-depth and future-proofs `sync init`.

LOW — secret leak to the transport command. runTransportCmd handed the whole
process.env (incl. KIT_MEMORY_PASSPHRASE) to the operator's push/pull command,
which only ever needs to move the already-encrypted blob. A command that logs its
env would spill the passphrase next to the ciphertext. The child env is now
stripped of kit-managed PASSPHRASE/SECRET/TOKEN/PASSWORD/KEY vars; provider creds
(AWS_*, etc.) still pass through.

2 new tests: loadSyncConfig rejects option-injecting remote/branch + ext::; the
transport child env never contains KIT_MEMORY_PASSPHRASE. Full suite 1981 green.

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 d9b14b6 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