From 8a32c827988e9900a9187e68a86fbeb63d4ab4ff Mon Sep 17 00:00:00 2001 From: Doug Mealing Date: Fri, 20 Nov 2026 05:33:47 -0500 Subject: [PATCH 1/3] feat(hooks): refuse commits and pushes whose author or committer identity matches the private denylist --- .githooks/identity-scan.sh | 60 +++++++++++++++++++++++++ .githooks/pre-commit | 5 +++ .githooks/pre-push | 24 +++++++++- CONTRIBUTING.md | 6 ++- scripts/leak-scan.test.ts | 91 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 183 insertions(+), 3 deletions(-) create mode 100755 .githooks/identity-scan.sh diff --git a/.githooks/identity-scan.sh b/.githooks/identity-scan.sh new file mode 100755 index 0000000000..2722c06d38 --- /dev/null +++ b/.githooks/identity-scan.sh @@ -0,0 +1,60 @@ +#!/usr/bin/env bash +# +# Refuse author/committer identities that match the private denylist. metaobjects is PUBLIC and +# a commit's author and committer name and email travel with it, but the added-line scan never +# sees them. Same denylist source as .githooks/pre-commit (git config hooks.denyListPath, else +# .githooks/deny-list.local); this script names NO private term and prints none: it reports +# only that an identity matched, and whether it was the author or the committer. +# +# Usage: +# .githooks/identity-scan.sh staged # the identity git would record for a new commit +# .githooks/identity-scan.sh range # every commit selected, by SHA only +# +# Exit 0 clean (or no denylist), 1 matched. +set -uo pipefail + +ROOT="$(git rev-parse --show-toplevel 2>/dev/null || echo .)" +# shellcheck source=leak-patterns.sh +. "$ROOT/.githooks/leak-patterns.sh" + +DENY_FILE="$(git config --get hooks.denyListPath 2>/dev/null || true)" +[ -z "$DENY_FILE" ] && DENY_FILE="$ROOT/.githooks/deny-list.local" +[ -f "$DENY_FILE" ] || exit 0 +PATTERNS=$(grep -vE '^[[:space:]]*(#|$)' "$DENY_FILE" | paste -sd'|' -) +[ -n "$PATTERNS" ] || exit 0 + +# 0 when the identity text matches the denylist after the maintainer's allowed address is removed. +matches() { + printf '%s\n' "$1" | sed -E "s/$LEAK_ALLOW//Ig" | grep -qEi "$PATTERNS" +} + +mode="${1:-}" +[ $# -gt 0 ] && shift +bad=0 +case "$mode" in + staged) + for role in AUTHOR COMMITTER; do + ident=$(git var "GIT_${role}_IDENT" 2>/dev/null) || continue + if matches "${ident% * *}"; then # drop the trailing " " + echo " commit blocked — the $(echo "$role" | tr A-Z a-z) identity git would record matches the private denylist (metaobjects is PUBLIC)." >&2 + bad=1 + fi + done + [ "$bad" -eq 1 ] && echo " Set a public identity for this repo (git config user.name / user.email)." >&2 + ;; + range) + shas="" + while IFS=$'\t' read -r sha an ae cn ce; do + if matches "$an $ae $cn $ce"; then shas="$shas $sha"; fi + done < <(git log --format='%H%x09%an%x09%ae%x09%cn%x09%ce' "$@" 2>/dev/null) + if [ -n "$shas" ]; then + echo "" >&2 + echo " push blocked — author or committer identity matches the private denylist on:" >&2 + for s in $shas; do echo " $s" >&2; done + echo " Rewrite those commits with a public identity (metaobjects is PUBLIC)." >&2 + bad=1 + fi + ;; + *) echo "usage: identity-scan.sh staged | range " >&2; exit 2 ;; +esac +exit "$bad" diff --git a/.githooks/pre-commit b/.githooks/pre-commit index 6eaae8e1c0..5a18f2a267 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -41,6 +41,11 @@ hits=$(git diff --cached --diff-filter="$LEAK_DIFF_FILTER" -U0 --no-color 2>/dev /^\+/ && !/^\+\+\+/ { if (f !~ /^\.githooks\//) print f "\t" substr($0,2) } ' | grep -Ei "$PATTERNS" | grep -vEi "$ALLOW") +# The author/committer identity git would record must not match the denylist either. +if [ -x "$ROOT/.githooks/identity-scan.sh" ]; then + "$ROOT/.githooks/identity-scan.sh" staged || exit 1 +fi + # A pre-release version must never be committed: scripts/release.mjs derives the lockstep # set from the CLI's CURRENT version, so a stray -rc.N silently shrinks the next release. # Only runs when a version-bearing file is actually staged. diff --git a/.githooks/pre-push b/.githooks/pre-push index c2dcd84fef..75a08e176f 100755 --- a/.githooks/pre-push +++ b/.githooks/pre-push @@ -19,6 +19,27 @@ # set -uo pipefail +# Read the pushed refs once (stdin: ); both the +# identity guard and the TS gate below use them. +ZERO="0000000000000000000000000000000000000000" +_PUSH_REFS="$(cat)" + +# ── Identity guard: no outgoing commit may carry an author/committer identity that matches the +# private denylist. Runs first and ignores SKIP_TS_TYPECHECK. A new branch is checked against +# every commit not already on a remote. +_IDENT_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || echo .)" +if [ -x "$_IDENT_ROOT/.githooks/identity-scan.sh" ]; then + while read -r _lr localsha _rr remotesha; do + [ -z "${localsha:-}" ] && continue + [ "$localsha" = "$ZERO" ] && continue + if [ "$remotesha" = "$ZERO" ]; then + "$_IDENT_ROOT/.githooks/identity-scan.sh" range "$localsha" --not --remotes || exit 1 + else + "$_IDENT_ROOT/.githooks/identity-scan.sh" range "$remotesha..$localsha" || exit 1 + fi + done <<< "$_PUSH_REFS" +fi + # ── Always-run, toolchain-free guard (BEFORE the TS-skip below — unrelated gate). # Reactor-excluded Java/Kotlin integration-test poms must track the reactor # . They are outside the reactor, so a release `versions:set` skips them; @@ -40,7 +61,6 @@ if [ "${SKIP_TS_TYPECHECK:-}" = "1" ]; then fi ROOT="$(git rev-parse --show-toplevel 2>/dev/null || echo .)" -ZERO="0000000000000000000000000000000000000000" # Collect the files changed across every ref being pushed (stdin: # ). A brand-new branch (remote sha = zeros) has no remote base, @@ -59,7 +79,7 @@ while read -r _localref localsha _remoteref remotesha; do files="$(git diff --name-only "$remotesha..$localsha" 2>/dev/null || true)" changed="$changed $files" -done +done <<< "$_PUSH_REFS" # Skip the (slow) gate when the push touches no TypeScript sources. if [ "$run_gate" -ne 1 ]; then diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 076b7c2177..4b9ab32192 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -21,7 +21,11 @@ conformance corpora. This guide covers how to propose changes. client names, personal information, or absolute local paths in code, docs, fixtures, **or commit messages**. Use generic terms ("a downstream consumer", "a sibling project") and repo-relative paths (``). A local pre-commit hook enforces - this, and `scripts/ci-local.sh` re-runs the same leak scan over your branch. + this, and `scripts/ci-local.sh` re-runs the same leak scan over your branch. With a + private denylist configured, the hooks also refuse a commit (pre-commit) or push + (pre-push) whose author or committer name or email matches it. Hosted CI cannot see + the private denylist, so that identity check protects only machines with the hooks + installed. ## How to contribute a change diff --git a/scripts/leak-scan.test.ts b/scripts/leak-scan.test.ts index d0d19225a5..d9cc531de6 100644 --- a/scripts/leak-scan.test.ts +++ b/scripts/leak-scan.test.ts @@ -86,3 +86,94 @@ describe("leak-scan", () => { expect(scan(dir, "pre-commit").status).toBe(1); }); }); + +describe("identity scan (author and committer vs the private denylist)", () => { + // Synthetic denylist and identities only; nothing here names a real person or employer. + const deny = () => { + const f = join(tmp, "deny.txt"); + writeFileSync(f, "# synthetic\nacmecorp\n"); + return f; + }; + function identityFixture(): string { + const dir = fixture(); + cpSync(join(REPO, ".githooks", "identity-scan.sh"), join(dir, ".githooks", "identity-scan.sh")); + git(dir, "config", "hooks.denyListPath", deny()); + return dir; + } + function run(dir: string, args: string[], env: Record = {}) { + const r = spawnSync("bash", [join(dir, ".githooks", "identity-scan.sh"), ...args], { + cwd: dir, + encoding: "utf8", + env: { ...process.env, ...env }, + }); + return { status: r.status, out: `${r.stdout}${r.stderr}` }; + } + const bad = { GIT_AUTHOR_NAME: "Pat", GIT_AUTHOR_EMAIL: "pat@acmecorp.example" }; + const good = { GIT_COMMITTER_NAME: "Sam", GIT_COMMITTER_EMAIL: "sam@example.com" }; + + test("a denylisted author email blocks a commit and names only the role", () => { + const dir = identityFixture(); + const r = run(dir, ["staged"], { ...good, ...bad }); + expect(r.status).toBe(1); + expect(r.out).toContain("author"); + expect(r.out).not.toContain("committer"); + expect(r.out.toLowerCase()).not.toContain("acmecorp"); + }); + + test("a denylisted committer name blocks a commit", () => { + const dir = identityFixture(); + const r = run(dir, ["staged"], { + GIT_AUTHOR_NAME: "Sam", + GIT_AUTHOR_EMAIL: "sam@example.com", + GIT_COMMITTER_NAME: "AcmeCorp Bot", + GIT_COMMITTER_EMAIL: "bot@example.com", + }); + expect(r.status).toBe(1); + expect(r.out).toContain("committer"); + }); + + test("a clean identity passes, and so does no denylist at all", () => { + const dir = identityFixture(); + const clean = { GIT_AUTHOR_NAME: "Sam", GIT_AUTHOR_EMAIL: "sam@example.com", ...good }; + expect(run(dir, ["staged"], clean).status).toBe(0); + git(dir, "config", "hooks.denyListPath", join(tmp, "missing.txt")); + expect(run(dir, ["staged"], { ...good, ...bad }).status).toBe(0); + }); + + test("the pre-commit hook refuses a denylisted identity", () => { + const dir = identityFixture(); + cpSync(join(REPO, ".githooks", "pre-commit"), join(dir, ".githooks", "pre-commit")); + const r = spawnSync("bash", [join(dir, ".githooks", "pre-commit")], { + cwd: dir, + encoding: "utf8", + env: { ...process.env, ...good, ...bad }, + }); + expect(r.status).toBe(1); + }); + + test("a range scan lists only the SHAs of commits with a denylisted identity", () => { + const dir = identityFixture(); + writeFileSync(join(dir, "c.md"), "x\n"); + git(dir, "add", "-A"); + const env = { ...process.env, ...bad, ...good }; + const c = spawnSync("git", ["commit", "-q", "-m", "tainted"], { cwd: dir, env }); + expect(c.status).toBe(0); + const sha = spawnSync("git", ["rev-parse", "HEAD"], { cwd: dir, encoding: "utf8" }).stdout.trim(); + const r = run(dir, ["range", "HEAD~1..HEAD"]); + expect(r.status).toBe(1); + expect(r.out).toContain(sha); + expect(r.out.toLowerCase()).not.toContain("acmecorp"); + expect(run(dir, ["range", "HEAD~1..HEAD~1"]).status).toBe(0); + }); + + test("the maintainer's allowed address is not treated as a match", () => { + const dir = identityFixture(); + writeFileSync(join(tmp, "deny.txt"), "dougmealing\n"); + const r = run(dir, ["staged"], { + GIT_AUTHOR_NAME: "Doug", + GIT_AUTHOR_EMAIL: "doug@dougmealing.com", + ...good, + }); + expect(r.status).toBe(0); + }); +}); From 14d628fea084c3306bcc4e9492fccdcfbb446c83 Mon Sep 17 00:00:00 2001 From: Doug Mealing Date: Fri, 20 Nov 2026 05:37:22 -0500 Subject: [PATCH 2/3] no-mistakes(review): Fail closed on bad range; portable identity match --- .githooks/identity-scan.sh | 10 +++++-- scripts/leak-scan.test.ts | 54 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/.githooks/identity-scan.sh b/.githooks/identity-scan.sh index 2722c06d38..dd2b685089 100755 --- a/.githooks/identity-scan.sh +++ b/.githooks/identity-scan.sh @@ -25,7 +25,7 @@ PATTERNS=$(grep -vE '^[[:space:]]*(#|$)' "$DENY_FILE" | paste -sd'|' -) # 0 when the identity text matches the denylist after the maintainer's allowed address is removed. matches() { - printf '%s\n' "$1" | sed -E "s/$LEAK_ALLOW//Ig" | grep -qEi "$PATTERNS" + printf '%s\n' "$1" | tr '[:upper:]' '[:lower:]' | sed -E "s/$LEAK_ALLOW//g" | grep -qEi "$PATTERNS" } mode="${1:-}" @@ -44,9 +44,15 @@ case "$mode" in ;; range) shas="" + if ! log=$(git log --format='%H%x09%an%x09%ae%x09%cn%x09%ce' "$@" 2>&1); then + echo "" >&2 + echo " push blocked — cannot list the commits to scan (unresolvable range); fetch the remote and retry:" >&2 + echo "$log" | sed 's/^/ /' >&2 + exit 1 + fi while IFS=$'\t' read -r sha an ae cn ce; do if matches "$an $ae $cn $ce"; then shas="$shas $sha"; fi - done < <(git log --format='%H%x09%an%x09%ae%x09%cn%x09%ce' "$@" 2>/dev/null) + done <<< "$log" if [ -n "$shas" ]; then echo "" >&2 echo " push blocked — author or committer identity matches the private denylist on:" >&2 diff --git a/scripts/leak-scan.test.ts b/scripts/leak-scan.test.ts index d9cc531de6..7aa0bfbbab 100644 --- a/scripts/leak-scan.test.ts +++ b/scripts/leak-scan.test.ts @@ -166,6 +166,60 @@ describe("identity scan (author and committer vs the private denylist)", () => { expect(run(dir, ["range", "HEAD~1..HEAD~1"]).status).toBe(0); }); + test("a range that cannot be resolved blocks instead of passing", () => { + const dir = identityFixture(); + const r = run(dir, ["range", `${"1".repeat(40)}..HEAD`]); + expect(r.status).toBe(1); + expect(r.out).toContain("push blocked"); + }); + + describe("pre-push wiring", () => { + const ZERO = "0".repeat(40); + function pushFixture() { + const dir = identityFixture(); + cpSync(join(REPO, ".githooks", "pre-push"), join(dir, ".githooks", "pre-push")); + const rev = () => spawnSync("git", ["rev-parse", "HEAD"], { cwd: dir, encoding: "utf8" }).stdout.trim(); + const base = rev(); + writeFileSync(join(dir, "c.md"), "x\n"); + git(dir, "add", "-A"); + return { dir, base, commit: (env: Record) => { + const c = spawnSync("git", ["commit", "-q", "-m", "next"], { cwd: dir, env: { ...process.env, ...env } }); + expect(c.status).toBe(0); + return rev(); + } }; + } + function push(dir: string, line: string) { + const r = spawnSync("bash", [join(dir, ".githooks", "pre-push")], { + cwd: dir, + encoding: "utf8", + input: `${line}\n`, + env: { ...process.env, SKIP_TS_TYPECHECK: "1" }, + }); + return { status: r.status, out: `${r.stdout}${r.stderr}` }; + } + + test("a new branch carrying a denylisted identity is refused", () => { + const { dir, commit } = pushFixture(); + const head = commit({ ...bad, ...good }); + const r = push(dir, `refs/heads/x ${head} refs/heads/x ${ZERO}`); + expect(r.status).toBe(1); + expect(r.out).toContain(head); + }); + + test("an update carrying a denylisted identity is refused, a clean one passes", () => { + const { dir, base, commit } = pushFixture(); + const head = commit({ ...bad, ...good }); + expect(push(dir, `refs/heads/main ${head} refs/heads/main ${base}`).status).toBe(1); + expect(push(dir, `refs/heads/main ${base} refs/heads/main ${base}`).status).toBe(0); + }); + + test("an update whose remote sha is unknown locally is refused", () => { + const { dir, commit } = pushFixture(); + const head = commit({ ...good, GIT_AUTHOR_NAME: "Sam", GIT_AUTHOR_EMAIL: "sam@example.com" }); + expect(push(dir, `refs/heads/main ${head} refs/heads/main ${"1".repeat(40)}`).status).toBe(1); + }); + }); + test("the maintainer's allowed address is not treated as a match", () => { const dir = identityFixture(); writeFileSync(join(tmp, "deny.txt"), "dougmealing\n"); From 1a4605f147f0ac15b322c53104f65d93346f5c3c Mon Sep 17 00:00:00 2001 From: Doug Mealing Date: Fri, 20 Nov 2026 05:48:48 -0500 Subject: [PATCH 3/3] no-mistakes(document): Document identity guard in hook docs --- .githooks/deny-list.example | 1 + .githooks/leak-patterns.sh | 12 +++++++----- .githooks/pre-commit | 3 ++- .githooks/pre-push | 8 +++++--- CONTRIBUTING.md | 7 ++++--- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/.githooks/deny-list.example b/.githooks/deny-list.example index f9822df47d..52c7e3ca43 100644 --- a/.githooks/deny-list.example +++ b/.githooks/deny-list.example @@ -2,6 +2,7 @@ # # Copy to deny-list.local (which is gitignored) and add the real private/other-project # names you want blocked, one extended-regex per line. Blank lines and #-comments ignored. +# The same list is matched against commit author and committer names and emails (identity-scan.sh). # Keeping the real names ONLY in the untracked .local file ensures this PUBLIC repo's # committed files never name a private project. # diff --git a/.githooks/leak-patterns.sh b/.githooks/leak-patterns.sh index a62ab53856..aefb333e07 100644 --- a/.githooks/leak-patterns.sh +++ b/.githooks/leak-patterns.sh @@ -1,5 +1,6 @@ -# Shared leak-scan patterns, sourced by .githooks/pre-commit and .githooks/leak-scan.sh so the -# local hook and the hosted `leak-scan` status can never disagree about what a leak is. +# Shared leak-scan patterns, sourced by .githooks/pre-commit, .githooks/identity-scan.sh and +# .githooks/leak-scan.sh so the local hooks and the hosted `leak-scan` status can never disagree +# about what a leak is. # Names NO private project; private names come only from the untracked denylist. # # /Users/ is the macOS home shape. It was missing from leak-scan.sh until a rename-with-edits @@ -8,9 +9,10 @@ # Generic, non-sensitive structural patterns (safe to commit): LEAK_PATTERNS='/home/[A-Za-z0-9._-]+/|/Users/[A-Za-z0-9._-]+/|~/Development' -# Legitimate matches to ignore. The maintainer's email, allowed so the npm manifests' author -# line could commit; no manifest has carried it since 1.3.0 (author "MetaObjects contributors"), -# so the allow is vestigial — a candidate for removal next time the hook changes. +# Legitimate matches to ignore. The maintainer's email. Content scans drop it from added lines; +# identity-scan.sh strips it before matching the author/committer identity, so the maintainer's +# own commits pass a denylist that names the maintainer. (The npm manifests no longer carry it, +# since 1.3.0 — author "MetaObjects contributors" — so that was its original reason.) LEAK_ALLOW='doug@dougmealing\.com' # Diff filter: Added, Copied, Modified and Renamed (a `git mv` plus an edit is a rename). diff --git a/.githooks/pre-commit b/.githooks/pre-commit index 5a18f2a267..10eba5a718 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -1,7 +1,8 @@ #!/usr/bin/env bash # # metaobjects is a PUBLIC repository. -# Block commits that leak absolute local paths, or private/other-project names. +# Block commits that leak absolute local paths, or private/other-project names, or whose +# author/committer identity matches the private denylist (.githooks/identity-scan.sh). # # IMPORTANT: this committed hook names NO private project. The structural # patterns below are generic (home paths). Private project names live ONLY in an diff --git a/.githooks/pre-push b/.githooks/pre-push index 75a08e176f..6892d1a480 100755 --- a/.githooks/pre-push +++ b/.githooks/pre-push @@ -9,13 +9,15 @@ # the push when it is red. Loud by design — nothing red should leave your machine # quietly. # -# Scope: only the TypeScript build+typecheck gate (the one local `bun test` skips). +# Scope: the TypeScript build+typecheck gate (the one local `bun test` skips), plus the +# identity guard (.githooks/identity-scan.sh: outgoing author/committer identities vs the private +# denylist), which runs first and ignores SKIP_TS_TYPECHECK. # The Java / C# / Python compile+conformance gates stay CI-only (too heavy + toolchain # -dependent for a push hook); branch protection still requires them on PRs. # # Activate (one-time, per clone): git config core.hooksPath .githooks -# Bypass (emergencies only): git push --no-verify -# SKIP_TS_TYPECHECK=1 git push +# Bypass (emergencies only): git push --no-verify (skips both guards) +# SKIP_TS_TYPECHECK=1 git push (skips the TS gate only) # set -uo pipefail diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4b9ab32192..8c35a9e1f6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -147,9 +147,10 @@ integration suite and the TypeScript `codegen-ts` conformance suite, and the JVM integration modules' surefire forks. It SKIPS (loudly, not silently) any port whose toolchain (bun/dotnet/uv/mvn) isn't -installed. The `.githooks/pre-push` hook additionally runs the TS build+typecheck -gate and a Java pom-version drift guard on every push (activate hooks once per -clone: `git config core.hooksPath .githooks`). +installed. The `.githooks/pre-push` hook additionally runs the identity guard (the +author and committer of every outgoing commit against the private denylist; not skipped by +`SKIP_TS_TYPECHECK=1`), the TS build+typecheck gate and a Java pom-version drift guard on +every push (activate hooks once per clone: `git config core.hooksPath .githooks`). If you drive changes through the no-mistakes validation gate, `.no-mistakes.yaml` pins its `test` step to `scripts/ci-local.sh --affected --strict-toolchains` and its `lint` step to