You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Harden git invocations on cached repositories - #4902
Git always reads a repository's own config. APM keeps some repositories between runs, so their config is now validated against an allow-list before any git run, and is never used otherwise.
Owner:src/apm_cli/cache/cached_repo.py
require_trusted_cached_repo() / cached_repo_is_trusted() parse config (and config.worktree) in-process; nothing is executed. A repository is accepted only when every key is one APM writes, with a value APM would write:
core.* repository basics and the line-ending and symlink pins
remote.origin.url, which must name the repository the cache entry is keyed by (its shard, or the local bare a checkout was cloned from)
branch.<name>.{remote,merge}
Notes on the allowed keys:
apm.*: APM writes exactly two keys, apm.linkMaterialization=git-objects-checkout and apm.sparseMaterialization=complete. They are only compared for equality, in git_cache._checkout_config_values, and are never used as a command, path or URL. Git ignores the apm section, and the allow-list restricts their values to [a-z0-9-]+.
branch.<name>.merge: accepts Git's branch-name syntax (for example release+prod or team@main) but rejects whitespace, control characters, ~^:?*[\, .., // and @{. So it can never be read as a URL, a refspec, a path or a revision expression. APM never reads it, and it never chooses a fetch source; the allow-list only checks its shape.
Everything else is refused, including subsection forms ([http "<url>"], [credential "<url>"], [url "<x>"]), includes and anything unparseable.
The check also refuses:
commondir and info/attributes
active (non-.sample) hooks
objects/info/http-alternates
object alternates in a bare
object alternates in a checkout that point outside the git cache
Inert runs.inert_git_args() and cached_repo_env() apply to every git run in these repositories:
core.hooksPath=/dev/null and core.fsmonitor=false
GIT_TERMINAL_PROMPT=0
GIT_ASKPASS=echo unless APM already set it
GIT_ALLOW_PROTOCOL=file:http:https:ssh, so no ext, fd or plaintext git:// transports (git:// is already rejected as a dependency transport)
Global and system config keep their existing handling: network runs already freeze them via git_network_env.
What a refused repository does:
A cache bare or checkout is discarded and rebuilt.
A fetch into an untrusted bare is refused.
A read-only lookup treats it as a miss.
A native snapshot raises CodexNativeError.
Guard:transport-platform-cached-repo-git (owner record + MutationCases). It is an AST rule plus literal pins:
In each guarded file, every git runner's argv carries the inert args.
In the cache and snapshot files, env comes from cached_repo_env().
Only cache/git_cache.py may resolve the git cache buckets.
_bare_has_sha and _fetch_into_bare_locked must open with the bare trust check; a MutationCase removes each one.
The trust checks stay at every point a persisted repository is opened.
The unlocked cache-hit probe never evicts. An untrusted checkout is evicted only by _create_checkout's locked re-probe.
Refusal messages are redacted before they are logged.
Git runs inside APM-persisted state
Site
Repository kind
Routed through the owner
cache/git_cache.py_fetch_into_bare_locked (SHA fetch and fallback)
git cache bare (db_v1)
yes: trust check first (refuse), fenced env, inert args
the user's own repository enclosing a deployed file
inert args (no config check: not an APM repository)
legacy_lock_evidence runs status inside the user's own repository, so that repository's own filters apply by design; it is not cache-restorable.
Other git runs operate on fresh per-run temp repositories or on user-owned repositories, not on APM-persisted state: the shared clone cache in deps/bare_cache.py, the downloader temp clones, deps/git_file_transport.py, validation and ref-resolution temp repos, the local-marketplace git show, and policy/_remote.py / policy/ci_checks.py in the project root. policy_v1 and http_v1 hold files only.
Issue and approved scope
Issue: scope approved by the maintainers; see the linked ruling.
Human scope-approval comment: scope approved by the Quality & Lifecycle owner.
Does this PR complete the issue, or what remains? It completes the cached-repository hardening.
Type of change
Bug fix
New feature
Documentation
Maintenance / refactor
Testing
Tested locally
All existing tests pass
Added tests for new functionality (if applicable)
tests/integration/test_cached_repo_config.py has 23 real-git cells:
Planted bare settings (12 cells). One APM-shaped cached bare per setting APM never writes: credential.helper (401 origin), http.proxy (407 proxy), URL-scoped http.<url>.proxy / credential.<url>.helper, include.path to a file outside the cache, core.fsmonitor, core.hooksPath, filter.*, core.sshCommand, core.gitProxy, http.sslVerify=false and url.<x>.insteadOf. Each drives GitCache.get_checkout for a commit the bare lacks, the path apm install --update takes, and asserts the entry is discarded and no configured command runs.
Active hook: an active hook in a cached bare is discarded.
Checkout: a cached checkout with an unexpected setting is rebuilt.
Side files (3 cells):info/attributes, commondir and out-of-cache alternates are refused.
Native snapshot: a snapshot with an unexpected setting is refused and nothing runs.
Control: an unmodified cached bare is reused as is, with no discard and no network.
User config: a local filter.lfs.* is refused even when the user's own global config defines the same driver. A local plus a URL-scoped credential.<url>.helper is refused alongside a user-global helper; the clone fails cleanly, as it does without them.
Lock order: an untrusted checkout is still present when the locked rebuild runs, so it is evicted only under its shard lock.
Redaction: a refused URL-scoped key never prints its credential.
Against main b8a12c29 the vector cells fail; the control passes. On this branch all 23 pass.
Tests that drive cache mechanics with fake (empty) repositories now use tests/utils/cached_repo_trust.py. Three real-git tests changed their expected outcome; each is now stricter:
A bare with a local URL rewrite is refused before fetching.
A bare with a sibling remote is refused. The fallback-refspec assertion still runs on an unmodified bare.
A checkout with core.autocrlf=true is refused rather than rematerialized.
One fragment per section, changelog.d/<pr>.<section>.md, holding
one line: user-visible effect first, 25 words or fewer, ending with (#PR); breaking changes only under upgrade notes; no Highlights; no
new lines under ## [Unreleased]. See changelog.d/README.md and .github/instructions/changelog.instructions.md.
Repositories APM keeps between runs (git cache bares and checkouts, native
snapshots) are now checked before any git run: their config is parsed
in-process and accepted only when every key is one APM writes, with a value
APM would write. Includes, side config files, active hooks and object
alternates that leave the cache are refused. A refused cache entry is
discarded and rebuilt. Every git run there is also inert: no hooks, no
fsmonitor, no terminal prompt, a fixed askpass and no ext/fd transports.
Owner: cache/cached_repo.py, guarded by transport-platform-cached-repo-git.
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Unresolved critical findings allow checkout deletion outside its lock, leave trust-check removal undetected by the architecture guard, and make the new test module violate the taxonomy ratchet.
This PR centralizes trust checks for Git repositories APM retains between runs, aiming to prevent cached repository settings from activating unexpected Git behavior.
git:// is already rejected as an insecure dependency transport, so cached
repository runs no longer allow it. Two cells show a repository-local filter
or credential helper is refused even when the user's own global config
defines a driver or helper of the same kind.
Co-authored-by: Copilot App <[email protected]>
The guard now requires the object probe and the fetch into a cached bare to
open with the owner's trust check, with a mutation for each. The unlocked
cache-hit probe no longer evicts; the locked re-probe does. Branch names
follow Git's own syntax, and a refusal message is redacted before it is
logged.
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Recursive alternates can escape the cache boundary, and persisted-cache Git callers bypass required protections without being detected by the architecture guards.
A valid default branch such as release"prod makes Git write [branch "release\"prod"], which this regex rejects because it forbids backslash escapes. Subsequent cache hits therefore rebuild the legitimate checkout, and read-only lookups miss. Accept Git's escaped quote/backslash syntax in subsection headers and add a reuse regression for a quoted default branch.
The L2 ref lookup asks GitCache.bare_ref_sha instead of opening a bare
itself, cached checkouts are link-checked through the owner, chained object
alternates are refused, and the guard checks each bare and checkout entry
point (one mutation case per guard).
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Cache-path validation gaps allow Git to access object databases outside the cache, while removal of _rev_parse leaves five existing tests failing before their assertions.
Preserve trailing spaces when validating alternates paths
src/apm_cli/cache/cached_repo.py:166
Git preserves trailing spaces in unquoted alternates paths, but this check removes them. An alternate ending in /db_v1/<shard>/objects is therefore validated against objects, even if the distinct objects path links outside the cache, allowing Git to read external objects. Resolve and inspect the exact pathname Git uses rather than trimming it.
Reject object directories that symlink outside the cache
src/apm_cli/cache/cached_repo.py:204
Only the Git directory itself is checked for symlinks, so a repository whose objects directory links outside the cache passes when the target has no alternates. Git can then read or write that external database during cached fetches or native snapshot commits. Reject linked object-directory paths through the existing path-security helper and add regressions for both repository types.
Accept escaped quotes in Git branch subsection headers
src/apm_cli/cache/cached_repo.py:34
For a valid default branch such as release"prod, Git writes [branch "release\"prod"], which this regex rejects because it forbids backslashes in subsection headers. Subsequent installs rebuild the valid checkout, and read-only lookups miss it. Accept Git's escaped quote/backslash syntax and add a reuse regression for a quoted default branch.
The tiered resolver's bare lookup and the downloader's cached-checkout link
check now go through GitCache.bare_ref_sha and cached_repo.validate_cached_links;
the guards that pinned the old call sites follow them with the same strictness.
Tests patch the new downloader seam.
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Removing _rev_parse leaves existing resolver tests patching a nonexistent method, causing AttributeError before execution; their cache doubles and assertions must be migrated to bare_ref_sha(url, ref).
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because unpublished critical findings show bypassable alternate-path validation and unfenced cached-checkout Git reads that can trigger network fetches.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because alternate-path validation can disagree with Git’s parsing, allowing access to object databases outside the cache despite containment checks.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Unresolved containment flaws allow Git to access object databases outside the cache, and symlinked object directories can receive writes during repair.
Object alternates are read line by line as written, without trimming. Git
state is read only from regular files. A cached repository needs a
well-formed HEAD, and snapshot Git commands name their repository
explicitly. Branch sections with escaped quotes are accepted.
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The absolute --git-dir argument reintroduces Git’s directory-length limit, causing native snapshot creation and repair to fail in deep paths, particularly on Windows.
Snapshot Git commands pass a relative Git directory and work tree, which
keeps paths short. HEAD is accepted with the trailing whitespace Git
trims. Unit fixtures lay down a HEAD like the repositories they model.
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because cache validation can accept checkouts missing required Git directories, allowing sparse probes to target an enclosing user repository and modify its configuration.
… inside it
Object payloads are checked like every other entry; objects/ and refs/ must
be present. Symbolic HEAD names follow Git's ref-name rules, and the HEAD
reader stays inside refs/ and returns only object ids. Config lines are
split only where Git splits them. Git runs on cached checkouts and
snapshots never look above the repository. An entry that Git's own
maintenance removes while it is listed is skipped.
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because cache-hit validation misses symlinks or FIFOs in alternate object databases, potentially allowing Git to read outside the cache or block.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because cache trust checks can miss tampered backing objects, potentially allowing external-file reads or blocked Git processes.
Owner registry and transport rule group take both sides: the deploy-store
owner and #4902's cached-repository git owner.
Co-authored-by: Copilot App <[email protected]>
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
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.
Description
Git always reads a repository's own config. APM keeps some repositories between runs, so their config is now validated against an allow-list before any git run, and is never used otherwise.
Owner:
src/apm_cli/cache/cached_repo.pyrequire_trusted_cached_repo()/cached_repo_is_trusted()parseconfig(andconfig.worktree) in-process; nothing is executed. A repository is accepted only when every key is one APM writes, with a value APM would write:core.*repository basics and the line-ending and symlink pinsextensions.partialclone/worktreeconfig/objectformatapm.*materialization pinsremote.origin.{fetch,tagopt,promisor,partialclonefilter}remote.origin.url, which must name the repository the cache entry is keyed by (its shard, or the local bare a checkout was cloned from)branch.<name>.{remote,merge}Notes on the allowed keys:
apm.*: APM writes exactly two keys,apm.linkMaterialization=git-objects-checkoutandapm.sparseMaterialization=complete. They are only compared for equality, ingit_cache._checkout_config_values, and are never used as a command, path or URL. Git ignores theapmsection, and the allow-list restricts their values to[a-z0-9-]+.branch.<name>.merge: accepts Git's branch-name syntax (for examplerelease+prodorteam@main) but rejects whitespace, control characters,~^:?*[\,..,//and@{. So it can never be read as a URL, a refspec, a path or a revision expression. APM never reads it, and it never chooses a fetch source; the allow-list only checks its shape.Everything else is refused, including subsection forms (
[http "<url>"],[credential "<url>"],[url "<x>"]), includes and anything unparseable.The check also refuses:
commondirandinfo/attributes.sample) hooksobjects/info/http-alternatesInert runs.
inert_git_args()andcached_repo_env()apply to every git run in these repositories:core.hooksPath=/dev/nullandcore.fsmonitor=falseGIT_TERMINAL_PROMPT=0GIT_ASKPASS=echounless APM already set itGIT_ALLOW_PROTOCOL=file:http:https:ssh, so noext,fdor plaintextgit://transports (git://is already rejected as a dependency transport)Global and system config keep their existing handling: network runs already freeze them via
git_network_env.What a refused repository does:
CodexNativeError.Guard:
transport-platform-cached-repo-git(owner record + MutationCases). It is an AST rule plus literal pins:envcomes fromcached_repo_env().cache/git_cache.pymay resolve the git cache buckets._bare_has_shaand_fetch_into_bare_lockedmust open with the bare trust check; a MutationCase removes each one._create_checkout's locked re-probe.Git runs inside APM-persisted state
cache/git_cache.py_fetch_into_bare_locked(SHA fetch and fallback)db_v1)cache/git_cache.py_bare_has_sha(cat-file)cache/git_cache.py_ensure_bare_repo(reuse or clone)cache/git_cache.pyget_checkouthit,_create_checkoutwrite-dedup and race re-probecheckouts_v1)cache/git_cache.py_read_only_checkoutcache/git_cache.py_unmaterialized_paths(ls-files),_pin_sparse_completeness(config), checkout clone/config/checkout,apply_sparse_cone,materialize_tracked_symlinksmarketplace/client.pycatalog fetchGitCache.get_checkout)codex_plugins/snapshot.py_git(hash-object,update-index,commit,rev-parse;repair_generation)apm_modulesinit, fenced env, inert argscore/legacy_lock_evidence.pygit_permits_legacy_adoption(rev-parse,ls-files,status)legacy_lock_evidencerunsstatusinside the user's own repository, so that repository's own filters apply by design; it is not cache-restorable.Other git runs operate on fresh per-run temp repositories or on user-owned repositories, not on APM-persisted state: the shared clone cache in
deps/bare_cache.py, the downloader temp clones,deps/git_file_transport.py, validation and ref-resolution temp repos, the local-marketplacegit show, andpolicy/_remote.py/policy/ci_checks.pyin the project root.policy_v1andhttp_v1hold files only.Issue and approved scope
Issue: scope approved by the maintainers; see the linked ruling.
Human scope-approval comment: scope approved by the Quality & Lifecycle owner.
Does this PR complete the issue, or what remains? It completes the cached-repository hardening.
Type of change
Testing
tests/integration/test_cached_repo_config.pyhas 23 real-git cells:credential.helper(401 origin),http.proxy(407 proxy), URL-scopedhttp.<url>.proxy/credential.<url>.helper,include.pathto a file outside the cache,core.fsmonitor,core.hooksPath,filter.*,core.sshCommand,core.gitProxy,http.sslVerify=falseandurl.<x>.insteadOf. Each drivesGitCache.get_checkoutfor a commit the bare lacks, the pathapm install --updatetakes, and asserts the entry is discarded and no configured command runs.info/attributes,commondirand out-of-cache alternates are refused.filter.lfs.*is refused even when the user's own global config defines the same driver. A local plus a URL-scopedcredential.<url>.helperis refused alongside a user-global helper; the clone fails cleanly, as it does without them.Against main
b8a12c29the vector cells fail; the control passes. On this branch all 23 pass.Tests that drive cache mechanics with fake (empty) repositories now use
tests/utils/cached_repo_trust.py. Three real-git tests changed their expected outcome; each is now stricter:core.autocrlf=trueis refused rather than rematerialized.Local runs (
pytest -n 2, targeted):tests/integration/test_cached_repo_config.pytests/unit/deps/,tests/unit/marketplace/,tests/unit/install/, downloader/sparse/lockfile-replay/Windows-symlink integration files-kinventory/registered/cached_repo)scripts/lint_architecture_boundaries.py --root .scripts/check_complexity_ratchet.py --base-ref b8a12c29ruff check/ruff format --checkon changed filesChangelog
changelog.d/<pr>.<section>.md, holdingone line: user-visible effect first, 25 words or fewer, ending with
(#PR); breaking changes only under upgrade notes; no Highlights; nonew lines under
## [Unreleased]. Seechangelog.d/README.mdand.github/instructions/changelog.instructions.md.Spec conformance (OpenAPM v0.1)
CONFORMANCE.{md,json}regenerated