Research-3266: Upstream PR sweep tool and hook repository-location isolation¶
- Status: Active
- Workstream: PR #3266 (fork-local developer tooling and hook isolation)
- Last updated: 2026-11-03
Question¶
- How should the fork rebase, verify commit signatures, build, test, and force-push open pull requests authored from
VMAFx/netflix-vmaf-contributionsagainstNetflix/vmafwithout risking pushes to the wrong remote, signing foreign commits, leaking caller credentials into PR build scripts, or corrupting worktrees? - Why did running repository unit tests inside a
pre-commit/pre-pushhook mutate the caller checkout's.git/config(core.bare = true), and whichGIT_*environment variables must be stripped at both the hook bridge and child-process boundaries?
Sources¶
git(1)andgit-worktree(1)manual pages:GIT_DIR,GIT_WORK_TREE,GIT_INDEX_FILE,GIT_COMMON_DIR,GIT_OBJECT_DIRECTORY,GIT_ALTERNATE_OBJECT_DIRECTORIES, andGIT_CONFIG_PARAMETERS.- ADR-1333: credential variable sanitization (
scripts/ci/run_meson_test.py). scripts/git-hooks/framework-hooks.shandscripts/githooks/tests/test_install_hooks_env.py:pre-commit install-hooksenvironment isolation (pre-commit/pre-commit#3609, #3774).
Findings¶
- Hook
GIT_DIRleak into childgit init/git configcalls: Git exportsGIT_DIR(and in worktreesGIT_WORK_TREE,GIT_COMMON_DIR,GIT_INDEX_FILE) to hooks. When a test fixture executed under a hook runsgit init --bareorgit config core.bare truein a temporary directory without clearingGIT_DIR, Git targets the caller repository's.gitdirectory instead of the temporary directory. Similarly,GIT_CONFIG_PARAMETERScarriesgit -coverrides (core.bare=true) to child processes. - Defense 1 (
scripts/git-hooks/framework-hooks.sh):unset GIT_DIR GIT_WORK_TREE GIT_COMMON_DIR GIT_OBJECT_DIRECTORY GIT_ALTERNATE_OBJECT_DIRECTORIESbefore runningpre-commit, while keepingGIT_INDEX_FILEforpre-commit run(partial commits) and keepingenv -u GIT_INDEX_FILE -u GIT_DIR -u GIT_WORK_TREE -u GIT_OBJECT_DIRECTORYoninstall-hooks. - Defense 2 (
scripts/dev/upstream_pr_sweep.pygit_environment()): strip allGIT_*variables exceptGIT_CONFIG_*(excludingGIT_CONFIG_PARAMETERS),GIT_AUTHOR_*,GIT_COMMITTER_*, andGIT_SSH*. - Remote identity, ref qualification, and push safety:
- Substring checks on
origin(fork in url) accept lookalike repositories (VMAFx/vmafx-other, path prefixes, or query parameters) and miss divergentremote.origin.pushurlsettings. Parsing canonicalowner/repoacross HTTPS, SSH (ssh://anduser@host:owner/repo.git), and local paths—and checking bothgit remote get-url originandgit remote get-url --push --all originon--repoand the target worktree—prevents cross-repository pushes while redacting URL userinfo/query secrets from refusal logs. - Resolving
refs/remotes/origin/<branch>explicitly prevents a localrefs/heads/origin/<branch>ref from shadowing the remote-tracking tip. Fetchingupstreamandorigin/<branch>under--applyensures rebases and--force-with-leaseuse current remote tips. - Commit authorship and build environment isolation:
- Checking that every commit in
base..old_shahas an author and committer email in the operator's identity set beforegit rebase --gpg-signprevents signing untrusted third-party commits unless--allow-foreign-authorsis explicitly set. - Passing
build_environment()(which appliessanitize_process_environmentand an allow-list of compiler/build variables) tomeson setup,ninja, andmeson testprevents PR build files from readingGITHUB_TOKEN,GH_TOKEN,SSH_AUTH_SOCK, or cloud credentials. - Author verification and unsigned commit counting fail closed by refusing any PR range exceeding
MAX_PR_COMMITScommits instead of silently truncating the inspection. - Worktree registration, detached checkout, and locking:
- Verifying existing worktrees against
git worktree list --porcelainprevents modifying unrelated checkouts at candidate paths. - Preparing worktrees with
git checkout --detach <old_sha>avoidsgit checkout -B <branch>failures when<branch>is checked out in another worktree. - Acquiring a non-blocking
fcntl.flocklock (<worktree>.lock, withO_CREAT | O_EXCLfallback whenfcntlis unavailable) serializes concurrent sweeps targeting the same PR. - On platforms with
fcntlsupport, the lock file persists on disk after lock release to prevent inode-recreation race conditions between concurrent processes, while the non-flock fallback unlinks the lock file on release.
Alternatives explored¶
| Alternative | Verdict | Reason |
|---|---|---|
Keep ad-hoc shell scripts (uprebase.sh, upbuild.sh) outside the repository | Rejected | Untested shell scripts lacked GIT_DIR isolation, URL/lease validation, credential stripping during meson setup/ninja, and structured TSV error reporting. |
Check out refs/heads/<branch> in each PR worktree via git checkout -B | Rejected | Fails whenever <branch> is checked out in the main repository or another worktree; detached HEAD + HEAD:refs/heads/<branch> push refspec needs no local branch. |
Substring check fork in origin_url on fetch URL only | Rejected | Vulnerable to substring lookalikes, unvalidated pushurl overrides, and credential leakage in refusal messages. |
Open questions¶
- None.
Related¶
- ADRs: ADR-1333
- PRs: #3266
- Files:
scripts/dev/upstream_pr_sweep.py,scripts/dev/tests/test_upstream_pr_sweep.py,scripts/dev/tests/test_upstream_pr_sweep_hardening.py,scripts/dev/tests/upstream_pr_sweep_fixture.py,docs/development/upstream-pr-sweep.md,scripts/git-hooks/framework-hooks.sh,scripts/githooks/tests/test_install.py