Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .githooks/deny-list.example
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down
66 changes: 66 additions & 0 deletions .githooks/identity-scan.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/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 <rev-list args...> # 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" | tr '[:upper:]' '[:lower:]' | sed -E "s/$LEAK_ALLOW//g" | 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 "<epoch> <tz>"
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=""
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 <<< "$log"
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 <rev-list args>" >&2; exit 2 ;;
esac
exit "$bad"
12 changes: 7 additions & 5 deletions .githooks/leak-patterns.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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).
Expand Down
8 changes: 7 additions & 1 deletion .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -41,6 +42,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.
Expand Down
32 changes: 27 additions & 5 deletions .githooks/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,39 @@
# 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

# Read the pushed refs once (stdin: <localref> <localsha> <remoteref> <remotesha>); 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
# <version>. They are outside the reactor, so a release `versions:set` skips them;
Expand All @@ -40,7 +63,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: <localref> <localsha>
# <remoteref> <remotesha>). A brand-new branch (remote sha = zeros) has no remote base,
Expand All @@ -59,7 +81,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
Expand Down
13 changes: 9 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 (`<repo-root>`). 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

Expand Down Expand Up @@ -143,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
Expand Down
145 changes: 145 additions & 0 deletions scripts/leak-scan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,148 @@ 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<string, string> = {}) {
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("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<string, string>) => {
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");
const r = run(dir, ["staged"], {
GIT_AUTHOR_NAME: "Doug",
GIT_AUTHOR_EMAIL: "doug@dougmealing.com",
...good,
});
expect(r.status).toBe(0);
});
});
Loading