Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f94f696
feat: add mediated git and gh tools with repo pinning and secret hygiene
tmaiaroto Nov 28, 2026
c2d7886
docs: document mediated git/gh tools and default-enabled posture
tmaiaroto Nov 28, 2026
b7b5f5c
sec: harden git/gh tool push policy and secret gates against bypass
tmaiaroto Nov 28, 2026
7da02c1
sec: neutralize hostile repo config for all mediated and ambient git …
tmaiaroto Nov 29, 2026
6927aba
sec: block in-place interpreter writes to .git metadata in sandboxed …
tmaiaroto Nov 29, 2026
689c1d8
sec: gate raw git/gh shell commands by mediated-tool tier in bash
tmaiaroto Nov 29, 2026
32a1729
docs: document mediated git/gh tiering and push/PAT policy in the vib…
tmaiaroto Nov 29, 2026
f1685ab
feat: cover CI diagnostics with read-only gh run/workflow/pr checks s…
tmaiaroto Nov 29, 2026
d04f6ec
fix: normalize subcommand echo in mediated git/gh args instead of rej…
tmaiaroto Nov 29, 2026
32128ae
fix: fail closed on filter enumeration errors and accept long run IDs…
tmaiaroto Nov 29, 2026
fcf6d15
fix: steer workspace-pin denials away from escalated bash and scratch…
tmaiaroto Nov 29, 2026
90fc0e3
fix: apply filter blanking via git -c args; normalize seatbelt deny p…
tmaiaroto Nov 29, 2026
e1e9e12
chore: log gitenv argv and git version for filter-blanked invocations…
tmaiaroto Nov 29, 2026
692b7d9
chore: scope gitenv diagnostic log to filter-blanked invocations
tmaiaroto Nov 29, 2026
b00a88a
test: skip filter neutralization cases on gits that ignore -c blankin…
tmaiaroto Nov 29, 2026
2dd43ea
fix: enumerate filter drivers on every filter-capable git invocation
tmaiaroto Nov 29, 2026
e06df02
chore: suppress verified-false codeql taint flows in gitenv sinks
tmaiaroto Nov 29, 2026
58ab69e
feat: extend mediated git/gh allowlists with read-only log search and…
tmaiaroto Nov 29, 2026
af20452
test: validate code-scanning dismiss tier with a minimal valid invoca…
tmaiaroto Nov 29, 2026
03981eb
fix: send GitHub code-scanning dismissal API field values
tmaiaroto Nov 29, 2026
0072fab
fix: return pr checks table as normal output when checks fail
tmaiaroto Nov 29, 2026
e456f63
docs: update VIBE_CODING.md with current git/gh mediation and read-on…
tmaiaroto Nov 29, 2026
e98f582
sec: close CodeRabbit round findings on the mediated git/gh tools
tmaiaroto Dec 1, 2026
ec2abc0
fix: idle client-server daemon shuts down and race-test servers are f…
tmaiaroto Dec 1, 2026
144b834
sec: canonicalize push destinations so qualified refs follow the same…
tmaiaroto Dec 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 130 additions & 0 deletions GIT_SHELL_HARDENING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Git/Shell Security Hardening Tracking

Tracking file for the security fixes from the git/gh audit (P1 → P0 → P2).
Branch: `feat/sandboxed-git-gh-tool`.

## Phase 1 (P1) — Shared `internal/gitenv` + neutralize all ambient probes — DONE

- [x] `internal/gitenv` package owns the single neutralization policy
(`Env(kind)`, `Run(...)`); `gitNeutralizedEnv` in `pkg/agent/tools/git.go`
deleted; `ghNeutralizedEnv` uses `gitenv.Env(KindNetwork)`.
- [x] `protocol.ext.allow=never` pinned via `GIT_CONFIG_*` overrides.
- [x] `gpg.program` neutralized to a failing binary; `commit.gpgsign` /
`tag.gpgsign` forced false unless the host's **global** config opts in
(probed with `git config --global --get`, `GIT_CONFIG_NOSYSTEM=1`).
- [x] `GIT_CONFIG_NOSYSTEM=1` always; `GIT_CONFIG_GLOBAL` deliberately **not**
pointed at an empty file so host `user.name`/`user.email` keep working.
- [x] `credential.helper`: blanked for local subcommands; for network
subcommands (fetch/pull/push/ls-remote) the chain is reset with an empty
value and the host helper re-pinned at higher precedence, so gh auth /
Keychain / GCM keep working while repo-local helpers cannot register.
- [x] `--no-pager` prepended to every mediated and ambient git invocation
(covers `core.pager` and every `pager.<cmd>`); `--no-ext-diff` /
`--no-textconv` forced on `diff`/`show` and on `log` when the host git
supports them (v2.52+ gate; older gits fail closed on unknown options).
- [x] Dynamic `filter.<driver>.*` blanking: before `add`, `commit`, `diff`,
`log`, `show`, `checkout`, `status`, the repo's effective `filter.*`
drivers are enumerated with a neutralized `git config --includes --list`
(covers `.git/config`, `include.path`, `includeIf.*`, `config.worktree`)
and `clean`/`smudge`/`process`/`textconv` are blanked via env overrides.
- [x] Ambient probes routed through `internal/gitenv`: `pkg/config/load.go`
(`isInsideWorktree`, `worktreeRoot`), `pkg/agent/prompt/prompt.go`
(`getGitStatus`/`getGitBranch`/`getGitStatusSummary`/`getGitRecentCommits`),
`pkg/agent/tools/scan_secrets.go` (`runGit`). All use `--no-pager` via
`gitenv.Run`.
- [x] Regression tests:
- `TestGitExec_NeutralizesHostileSpawnSinks` — pager, per-cmd pager,
textconv, ext_diff, ext_protocol, credential_helper, gpg_program,
clean filter (direct, via `include.path`, via `config.worktree`),
process filter; raw-git control steps skip when a sink cannot fire on
the host git.
- `TestGitExec_CredentialHelperFill` — deterministic credential-helper
neutralization via `git credential fill`.
- `TestPromptHostileRepoGitStatus` — hostile fsmonitor fixture driven
through `prompt.Build`; marker check + legitimate status renders.
- `TestRunGit_HostileRepoNeutralized` — hostile clean filter driven
through `scan_secrets.runGit`; rev-parse sanity.

### Findings during Phase 1

- `git rm --cached` itself applies the clean filter — fixture resets must
use `git update-index --force-remove` (plumbing, no filtering).
- `gpg.program` must name an executable file; shell snippets are exec'd
literally by git.
- Modern git (2.27+) blocks `ext::` transport by default
(`protocol.ext.allow` default); our `never` override is defense in depth.
- `textconv` filters do not fire for non-tty `git diff`/`log -p` on git
2.55; the runtime check for that sink skips (honest control), the env
override is still asserted statically.

## Phase 2 (P0) — Tighten `.git/` write protection in `bash` — DONE

- [x] `internal/pathguard` `CommandWriteBlocked`: in-place interpreter
detection (`sed -i`/`-i.bak`/`--in-place`/bundled short flags,
`perl -pi`, `gawk -i inplace`) routes their file operands through the
protected-path gate; reads without the flag stay allowed; `git` itself
stays exempt.
- [x] macOS Seatbelt: `(deny file-write* (subpath "<ws>/.git"))` emitted
after the workspace allow; deny rules win over allows. Sanctioned
repository writes go through the host-mediated git tool or explicit
(unsandboxed) escalation.
- [x] Linux Landlock: limitation documented in `enforceLandlock`
(allowlist-only kernel, no deny hole inside the recursive RW grant);
the interpreter-layer fence plus Phase 1 host-side neutralization
remain the primary defense against `.git/config` tampering.
- [x] Regression tests: `TestConfinement_CommandWriteBlocked_InPlaceInterpreters`
(argv fence, reader/writer split, git exemption),
`TestSeatbeltProfileDeniesGitMetadataWrites`,
`TestSeatbeltProfileNoGitDenyWithoutWorkspace`, and new
`sed`/`perl` vectors in `TestRunGitMetadataWriteProtection`
(blocked attempts must error "repository metadata"; plain in-place
reads and legitimate writes unaffected).

## Phase 3 (P2) — Tool-aware raw `git`/`gh` tiering in `bash` — DONE

- [x] `pkg/agent/tools/rawgitgh.go`: `rawGitGhBypass` parses the shell
command with `mvdan.cc/sh/v3/syntax`, walks `CallExpr` nodes, and
delegates `git`/`gh` invocations to the mediated validators
(`validateGitInvocation` / `validateGhInvocation`) — the tier table in
`gitSpecs`/`ghSpecs` stays the single source of truth. The classifier
only runs when the mediated tool is registered (`gitTooling` /
`ghTooling`).
- [x] Read-only local commands validated as `gitTierReadOnly`
(`status`, `log`, `diff`, `rev-parse`, …) stay unblocked; anything else
(`commit`, `push`, `pull`, `fetch`, `merge`, `rebase`, `config`,
`remote`, `credential`, `worktree`, `gh` writes) routes to
`permissions.BypassShortcuts` — denied headless/YOLO, prompted
interactively. The ordinary permission `Request` is skipped for gated
commands (`BypassShortcuts` is strictly stronger).
- [x] Unsupported operations (`clone`, `submodule`, `gh api`) are gated
and remain reachable via explicit unsandboxed escalation.
- [x] Non-literal argv (expansions, substitutions) is unclassifiable:
raw `git`/`gh` invocations gate conservatively; a non-literal argv0
never gates.
- [x] `pkg/agent/tools/bash.go` wires the classifier after session
lookup; denials log `Raw git/gh shell command denied` and emit span
attributes `phosphor.security.raw_git_gh_gated` / `_denied`.
- [x] Regression tests: `TestRawGitGhBypass` (classifier table incl.
non-literal argv) and `TestBashTool_RawGitGhTiering` (raw `git commit`
/ `git push` / `gh pr create` hit `BypassShortcuts` and are denied
headless; `git status` stays unblocked).
`recordingPermissionService` tracks `bypassCount` separately from
`requestCount`.

### Findings during Phase 3

- `git rev-parse --show-toplevel` needed `--show-toplevel` added to the
`rev-parse` boolFlags allowlist — the tier validator's argument
allowlist gates reads too, so unknown flags conservatively gate.

## Verification after each phase

- `go vet ./internal/gitenv/... ./pkg/agent/... ./pkg/config/... ./pkg/shell/...`
- `go test ./pkg/agent/... ./pkg/config/... ./pkg/shell/... ./internal/gitenv/...`

Phase 1 verification (branch head): all listed packages pass.

Phase 3 verification (branch head): `go vet` clean across
`internal/gitenv`, `pkg/agent`, `pkg/config`, `pkg/shell`,
`internal/pathguard`, `pkg/sandbox`; `go test` green across all of them
plus `pkg/sandbox`.
3 changes: 2 additions & 1 deletion docs/INDEX.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ searchable through the `phosphor_docs` tool or by viewing any
| --- | --- |
| [tools/OVERVIEW.md](tools/OVERVIEW.md) | Catalog of all built-in agent tools. |
| [tools/edit_tools.md](tools/edit_tools.md) | `edit` and `multiedit`: matching, safety, and diagnostics. |
| [tools/SCAN_SECRETS.md](tools/SCAN_SECRETS.md) | Scanning files and git history for leaked credentials. |
|| [tools/SCAN_SECRETS.md](tools/SCAN_SECRETS.md) | Scanning files and git history for leaked credentials. |
|| [tools/GIT_GH_MEDIATION.md](tools/GIT_GH_MEDIATION.md) | Host-mediated `git`/`gh` tools: repo pinning, approval tiers, push policy, PAT override, and secret hygiene. |
| [tools/SEMANTIC_SEARCH.md](tools/SEMANTIC_SEARCH.md) | Embedding-based natural-language code search. |
| [tools/TOOL_SEARCH.md](tools/TOOL_SEARCH.md) | Deferred MCP tool schemas and on-demand discovery. |
| [tools/WORKSPACE_SEARCH.md](tools/WORKSPACE_SEARCH.md) | Zero-API full-text search over symbols and docs. |
Expand Down
Loading
Loading