Skip to content

fix: bound git calls, contain the v2 patch tool, complete Shell.Info - #91

Merged
alderpath merged 3 commits into
mainfrom
fix/review-batch
Nov 27, 2026
Merged

alderpath merged 3 commits into
mainfrom
fix/review-batch

Conversation

@alderpath

Copy link
Copy Markdown
Collaborator

Three defects from the 2026-11-26 security and SRE reviews. Each was proven red before the fix.

SRE — unbounded git on the shared blocking pool

run_git used Command::output() with no deadline. Those calls run on the same 16-thread blocking pool as every store read, so enough hostile git invocations remove the pool and stall every store-backed route. Now platform::run_with_deadline (30 s, kills on expiry, drains both pipes on threads); git apply uses the stdin variant with the same deadline; failures count in ocserve_vcs_git_errors_total{op} instead of looking like an empty result.

Security — the v2 patch tool wrote anywhere

apply used cwd.join(path) then fs::write with no verification: ../x, sub/dir/../../x, absolute paths, *** Move to: ../x, and .git/hooks/pre-commit all wrote outside the project. Containment moved into ocserve-store so the tools crate shares the one handle-verified primitive with the file routes; .git is refused by name (D-PATCH-NO-GIT-DIR). Rule 75 keeps a new unmarked write a build failure (planted control proven).

Shell.Info — #75 renamed one key and still failed validation

The rename to exit omitted shell, file, metadata, time, and list() added sessionID, which the closed schema forbids. All required keys are emitted; sessionID moved to session_owners() for the goal loop. D-SHELL-NO-FILE records that output stays in memory.

Verification

  • patch_refuses_to_escape_the_project_directory — 5 escape shapes refused, in-tree add succeeds; red when the unverified join is restored.
  • Rule 75 planted uncontained write detected; red when the allow:raw-write marker is removed.
  • run_with_deadline unit tests (success, timeout kills and names the label, output drained).
  • 125 workspace suites green on the i9, clippy -D warnings clean, guards 0 fail, matrix OK, docs clean.

K-GIT-DEADLINE, K-PATCH-CONTAIN, K-SHELL-INFO-SHAPE.

Three defects from the 2026-11-26 security and SRE reviews, each proven
red before the fix.

SRE: `run_git` used `Command::output()` with no deadline on the same
16-thread blocking pool as every store read, so ~16 `git` invocations
against a huge, network-mounted or hostile repository removed the pool
and stalled every store-backed route. `platform::run_with_deadline`
polls with a 30 s cap, kills on expiry, drains both pipes on threads and
returns `TimedOut`; `git apply` uses the stdin variant with the same
deadline. Failures count in `ocserve_vcs_git_errors_total{op}` instead
of being silently indistinguishable from an empty result.

Security: the v2 `patch` tool wrote with `cwd.join(path)` and no
verification, so `../x`, an absolute path and `*** Move to: ../x`
escaped the project and `.git/hooks/pre-commit` was writable. Containment
moved into `ocserve-store` so the tools crate shares the one
handle-verified primitive with the file routes; `.git` is refused by
name (D-PATCH-NO-GIT-DIR). Rule 75 keeps a new unmarked write a build
failure.

Shell.Info (#75 follow-up): the rename to `exit` still omitted `shell`,
`file`, `metadata` and `time`, and `list()` added `sessionID`, which the
closed schema forbids, so a strict client still rejected every response.
All required keys are emitted; `sessionID` moved to `session_owners()`
for the goal loop. `D-SHELL-NO-FILE` records that output stays in memory.

K-GIT-DEADLINE, K-PATCH-CONTAIN, K-SHELL-INFO-SHAPE.
The snapshot engine's `run_git` used `wait_with_output()` with no cap. It
runs on the prompt path (step-start/step-finish snapshots), i.e. on the same
16-thread blocking pool as every store read, so an unbounded `git` against a
huge or network-mounted repository would stall turns rather than one route.
stdout/stderr now drain on their own threads so a full pipe cannot deadlock
the wait loop (issue #80's lesson), and a timeout kills the child, counts in
`ocserve_snapshot_git_timeouts_total`, and returns -1 like any other git
failure. K-GIT-DEADLINE extended.
The move into `ocserve-store` failed both platform jobs: that crate roots at
`#![cfg_attr(not(test), forbid(unsafe_code))]`, so the module's Windows
(`GetFinalPathNameByHandleW`) and macOS (`F_GETPATH`) FFI, which carry
item-level `#[allow(unsafe_code)]`, is E0453 "overruled by previous forbid".

Weakening store's `forbid` would trade a hard invariant for a file move.
Instead containment is its own leaf crate with `#![deny(unsafe_code)]` (the
policy `ocserve-http` had, which permits documented item-level opt-ins) and no
workspace-internal dependencies. `ocserve-http` re-exports it under the old
path so every `crate::containment::` call site is unchanged, and `ocserve-tools`
depends on it directly for the `patch` tool.

The http crate's rustix/libc/windows-sys target deps were containment-only and
are removed; store's copies go with the module.
@alderpath
alderpath merged commit 3ecb79a into main Nov 27, 2026
15 checks passed
@alderpath
alderpath deleted the fix/review-batch branch November 27, 2026 12:47
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.

1 participant