fix(git-ui): harden agent repository-operation facade (defense-in-depth)#1653
Merged
oscharko merged 1 commit intoJun 28, 2026
Conversation
Two LOW-severity, non-exploitable defense-in-depth hardenings on the agent repository-operation facade surfaced by the Epic #1571 security-boundary review. The trust boundary was already intact; these tighten it symmetrically. 1. Bound the agent-facade idempotency cache. POST /api/git/agent/operations kept its idempotency replay map as an unbounded process-memory Map removed only on completion, so a client streaming many distinct idempotency keys could grow it without limit. Replace it with an IdempotencyCache (bounded LRU + TTL): settled replay entries self-evict past a size cap or after a TTL, while in-flight reservations are exempt from eviction so existing idempotency semantics (replay-on-same-key, conflict-on-key-reuse, reserve-before-settle) are preserved exactly. The handler takes an optional injectable cache for testing. 2. Reject C0 control chars in pathspecs at the requestGuards layer. isContainedPathspec now rejects TAB/LF/CR/NUL and all other C0 control / DEL chars, matching the network-ref REF_CONTROL_CHAR guard. Not exploitable today (pathspecs are literalized as :(literal)<value> after a "--" sentinel at the adapter) — this is symmetric defense-in-depth. Adds unit tests for LRU + TTL eviction, in-flight-reservation exemption, replay preservation, and TAB/LF/CR rejection. keiko-server gitDelivery suite 196 pass; keiko-tools git suite 287 pass. Refs #1577 #1571 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
e619143
into
feat/keiko-repository-centered-desktop-workflow
8 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Addresses the two LOW-severity, non-exploitable defense-in-depth hardening opportunities flagged during the independent acceptance-criteria audit of Epic #1571 on the agent repository-operation facade. The security-boundary review found the trust boundary intact; neither item is an acceptance failure. Both are tightened here with small, well-tested changes.
1. Bound the agent-facade idempotency cache (resource exhaustion, low)
POST /api/git/agent/operationskept its idempotency replay map (agentOperationsRoutes.ts) as an unbounded process-memoryMap, keyed byprojectId+idempotencyKey, with entries removed only on completion. A client streaming many distinct idempotency keys could grow it without limit.Mapwith anIdempotencyCache(bounded LRU + TTL): settled replay entries self-evict once over a size cap (DEFAULT_IDEMPOTENCY_MAX_ENTRIES = 1024) or past a TTL (DEFAULT_IDEMPOTENCY_TTL_MS = 10 min); each insert also opportunistically prunes expired entries so the map self-cleans even for keys never queried again.handleGitAgentOperationWithDelegatetakes an optional injectable cache (default = module singleton) so eviction and TTL are deterministically testable.2. Reject C0 control chars in pathspecs at the
requestGuardslayer (defense-in-depth, low, NOT exploitable)isContainedPathspec(requestGuards.ts) rejected NUL, leading-//, Windows-absolute prefixes and..segments, but not other C0 control characters (TAB/LF/CR).GIT_DELIVERY_PATHSPEC_CONTROL_CHARrejecting the full C0 control range plus DEL (which also subsumes the prior explicit NUL check), symmetric with the network-refREF_CONTROL_CHARguard used for remote aliases insyncRoutes.ts.:(literal)<value>after a--sentinel ingit-mutation-adapter.ts. This is symmetric defense-in-depth at the boundary.Tests
agentOperationsRoutes.test.ts: LRU eviction past the size cap, TTL expiry, prune-on-insert, in-flight-reservation exemption, concurrent-reservation retention, plus handler-path replay preservation, cache bounding over many keys, and re-delegation after TTL expiry.requestGuards.test.ts: asserts TAB/LF/CR/NUL/DEL pathspecs are rejected, valid pathspecs (incl. spaces) accepted, and pre-existing unsafe shapes still rejected.Verification (local)
npx vitest run packages/keiko-server/src/gitDelivery→ 14 files, 196 tests pass (was 183).prettier --check,eslint(type-aware), and package-localtsc -ball clean on changed files.Refs #1577 #1571
🤖 Generated with Claude Code