Files
xerj-org b8617dabaa chore(git): identity-guard hooks — stop concurrent-session identity leaks at commit time
Motivation
PR #231's commit 15082748 and PR #219's c16320bb (now in main) were
authored with a personal e-mail address instead of xerj-org
<git@xerj.org>, tripping the CLA check on #231 and putting a private
address into public history. This has happened before: main also
carries ten commits from early August authored with a third-party
address from another project.

Root cause
Many concurrent agent sessions share one clone: one .git, ~95 linked
worktrees, and — because extensions.worktreeConfig is unset — a single
shared repo-local config. The reflogs show the effective identity
flipping four times in the past week and reverting within seconds to
minutes each time (e.g. 2026-08-08 12:58:44 wrong → 12:58:54 correct;
21:01:27 wrong → 21:05:01 correct, with .git/config mtime 22:24). That
pattern is a transient override — an environment variable or a
momentary edit of the shared config by a concurrent session — not a
standing misconfiguration. An audit of every identity input on this
machine confirms all are correct at rest: global user.email, the shared
repo config (xerj-org <git@xerj.org>), zero per-worktree
config.worktree files, no core.hooksPath, no GIT_* env in shell
profiles, and no other clone of this repo. Nothing left to fix at
rest; the leak can only be caught at commit time.

What changed
scripts/git-hooks/ (new, agent-fleet machines only — not for personal
contributor checkouts):
- pre-commit: resolves the exact author/committer ident git is about to
  use (git var GIT_AUTHOR_IDENT / GIT_COMMITTER_IDENT, which see env
  overrides and config alike) and refuses anything but
  xerj-org <git@xerj.org> or xerj-org <xerj-org@users.noreply.github.com>.
- commit-msg: refuses Co-Authored-By Claude/Anthropic trailers
  (standing directive 2026-07-22).
- install.sh: copies both into the clone's shared .git/hooks (guarded:
  refuses if core.hooksPath is set or a different hook already exists).
  Because hooks are shared, one install covers every worktree.
- test.sh: scratch-repo self-test; first proves the pre-fix failure
  (without hooks, a leaked identity commits silently), then proves the
  guards (wrong config email / env author / env committer / wrong name /
  Claude trailer all refused; both sanctioned identities accepted).

Coverage stated honestly: pre-commit fires on git commit (incl.
--amend) but not on rebase/cherry-pick continuations, and --no-verify
bypasses it. Both observed leaks came through plain git commit, which
this intercepts.

Companion git-ops (already done, no code):
- 15082748 amended to 1b4ee45b (identical tree/parent/message/dates,
  identity-only change; git diff between them is empty) and
  force-pushed with a pinned lease to fix/issue-210-require-if-match;
  the stale local branch ref was CAS-updated so a stale re-push cannot
  resurrect the wrong author. @cla-bot check requested on #231.
- c16320bb is merged history; main is not rewritten (prevention only).

Evidence
- scripts/git-hooks/test.sh: 8/8 PASS.
- Hooks installed live on this machine; a probe commit with the leaked
  identity (via GIT_AUTHOR_EMAIL/GIT_COMMITTER_EMAIL) is refused with
  exit 1, and this very commit passes the guard with the sanctioned
  identity.
- PR #231 now shows author/committer xerj-org <git@xerj.org>, login
  xerj-org.
2026-08-08 22:31:40 +02:00

54 lines
2.1 KiB
Bash
Executable File

#!/bin/sh
# XERJ identity guard — pre-commit hook.
#
# FOR xerj-org AGENT-FLEET MACHINES ONLY. Do not install on a personal
# contributor checkout; it enforces the xerj-org committer identity.
#
# Why this exists: many concurrent agent sessions share one repository
# (one .git, many worktrees, one shared repo-local config). Twice on
# 2026-08-08 a session's transient identity override (env var or a
# momentary `git config user.email` edit of the shared config) leaked a
# personal e-mail address into commits that reached the public repo
# (PR #219 commit c16320bb, PR #231 commit 15082748), and on 2026-08-04
# the same mechanism leaked a third-party address into main. Config
# audits cannot stop a transient override; refusing the commit can.
#
# What it checks: the exact author and committer ident git is about to
# use (`git var` resolves env vars AND config, in the same order commit
# does). Anything but the sanctioned xerj-org identities is refused.
#
# Coverage note (honest): pre-commit runs on `git commit` (including
# --amend) but NOT on rebase/cherry-pick continuation commits, and
# `git commit --no-verify` bypasses it. It is a guard rail, not a
# security boundary.
allowed_1='xerj-org <git@xerj.org>'
allowed_2='xerj-org <xerj-org@users.noreply.github.com>'
# `git var GIT_AUTHOR_IDENT` -> "Name <email> epoch tz"; strip the date.
author=$(git var GIT_AUTHOR_IDENT | sed 's/ [0-9][0-9]* [+-][0-9][0-9]*$//')
committer=$(git var GIT_COMMITTER_IDENT | sed 's/ [0-9][0-9]* [+-][0-9][0-9]*$//')
fail=0
case "$author" in
"$allowed_1"|"$allowed_2") ;;
*) echo "identity-guard: refusing commit — author is '$author'" >&2; fail=1 ;;
esac
case "$committer" in
"$allowed_1"|"$allowed_2") ;;
*) echo "identity-guard: refusing commit — committer is '$committer'" >&2; fail=1 ;;
esac
if [ "$fail" -ne 0 ]; then
cat >&2 <<'EOF'
identity-guard: commits in this repository must be authored as
identity-guard: xerj-org <git@xerj.org>
identity-guard: fix with:
identity-guard: git config user.name xerj-org
identity-guard: git config user.email git@xerj.org
identity-guard: and unset any GIT_AUTHOR_* / GIT_COMMITTER_* overrides.
EOF
exit 1
fi
exit 0