Skip to content

Git repository check: refuse what git may take that the check would skip - #1921

Merged
nedtwigg merged 1 commit into
mainfrom
audit-git-discovery
Nov 30, 2026
Merged

nedtwigg merged 1 commit into
mainfrom
audit-git-discovery

Conversation

@nedtwigg

Copy link
Copy Markdown
Member

Nightly audit follow-up for docs/specs/security-local.md -> "Spawned programs" (S277), and the S164 and S153 rules that point at it. Before running git in a folder the user hasn't vouched for, localGitRepository must walk everything git will open. In a few places it disagreed with git about which repository git takes or which path a config value names. Each was reproduced with git 2.56.1, and each now refuses (fails closed):

  • Path config values. git strips :(optional) from an excludes or attributes file and expands ~user/ and %(prefix)/, so the check was judging a different path from the one git opens. A value with any of these prefixes is now refused. core.worktree takes no expansion in git, so ~ there is no longer expanded to the home directory.
  • Nested candidates. git asks only that objects and refs be searchable (access(X_OK)), which an executable file passes. The check skipped such a candidate and accepted an ancestor, and git then took the nested one. A candidate with HEAD, objects, and refs present but not all directories now refuses the lookup.
  • Refs that are links. git reads a linked HEAD or loose ref as a symbolic ref by its text, without following it. Such a ref is now refused.
  • Environment. untrustedGitEnv also drops an inherited GIT_OBJECT_DIRECTORY, which lets git take a candidate with no objects.

S277 gains one clause: the check must not pass over a candidate git might take below the repository it accepts. The rationale entry carries the git evidence.

Tests: seven fake-filesystem cases, a real-git test of nested .git and nested bare candidates, the existing real-git share test extended with an :(optional) value, and an env test. Each fix group, when reverted, turns a new test red. dor-lib-common tests pass (52, 2 skipped), as do the lib git-info/git-cli/git-upstream tests, the dor-tools-builtin folder-viewer tests, and the dor open-picker tests. lint:specs and lint:md pass. Not run on Windows.

🤖 Generated with Claude Code

The pre-git repository check now refuses, rather than walks past, a candidate
git directory git's own discovery would accept and the check would not (an
`objects` or `refs` that is a file, a linked `HEAD`), refuses a linked loose
ref, refuses the excludes and attributes pathname forms it does not resolve
(`:(optional)`, `%(prefix)/`), resolves `core.worktree` as git does, without
`~` expansion, and drops an inherited GIT_OBJECT_DIRECTORY from the untrusted
git environment.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying mouseterm with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4f81b6a
Status: ✅  Deploy successful!
Preview URL: https://daa5add2.mouseterm.pages.dev
Branch Preview URL: https://audit-git-discovery.mouseterm.pages.dev

View logs

@nedtwigg
nedtwigg merged commit 6304f0b into main Nov 30, 2026
14 checks passed
@nedtwigg
nedtwigg deleted the audit-git-discovery branch November 30, 2026 04:17
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