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
25 changes: 25 additions & 0 deletions .githooks/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,28 @@ git -C "$remote" show-ref --verify --quiet refs/heads/topic || status=$?
[ "$(git -C "$remote" rev-parse refs/heads/keep)" = "$base" ] ||
fail 'the deletion changed keep'
echo 'ok: deletion removes only the named ref'

git -C "$work" reset --hard -q "$clean"
personal_email='robin''@''mail.invalid'
GIT_AUTHOR_EMAIL="$personal_email" git -C "$work" commit --allow-empty -qm 'Personal author email'
if git -C "$work" push fixture HEAD:refs/heads/keep > "$tmp/refusal" 2>&1; then
fail 'a personal author email must stop the push'
fi
grep -q '^C3 commit-1-author:1$' "$tmp/refusal" || { cat "$tmp/refusal" >&2; fail 'expected C3 author refusal'; }
! grep -Fq "$personal_email" "$tmp/refusal" || { cat "$tmp/refusal" >&2; fail 'refusal leaked author email'; }

git -C "$work" reset --hard -q "$clean"
GIT_COMMITTER_EMAIL="$personal_email" git -C "$work" commit --allow-empty -qm 'Personal committer email'
if git -C "$work" push fixture HEAD:refs/heads/keep > "$tmp/refusal" 2>&1; then
fail 'a personal committer email must stop the push'
fi
grep -q '^C3 commit-1-committer:1$' "$tmp/refusal" || { cat "$tmp/refusal" >&2; fail 'expected C3 committer refusal'; }
! grep -Fq "$personal_email" "$tmp/refusal" || { cat "$tmp/refusal" >&2; fail 'refusal leaked committer email'; }

git -C "$work" reset --hard -q "$clean"
GIT_AUTHOR_EMAIL='41898282+synthetic-bot[bot]@users.noreply.github.com' \
GIT_COMMITTER_EMAIL='noreply@github.com' \
git -C "$work" commit --allow-empty -qm 'Bot author with GitHub web-flow committer'
git -C "$work" push fixture HEAD:refs/heads/keep ||
fail 'bot author with GitHub web-flow committer must pass'
echo 'ok: commit email checks enforce noreply, bot and web-flow committer rules'
2 changes: 2 additions & 0 deletions tools/privacy-check/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ sh .githooks/test.sh --fixtures-only

Inputs combine in one run. Exit 0 is no refusal, 1 a refusal, 2 bad arguments. Each refusal names its contract rule, input and line, never the matched text. A missing, empty or unreadable literals list refuses under `--require-literals`; each result says whether literals were used. Without `--base`, history is checked from the contract's public anchor; `--upstream REF` narrows it to the commits after the merge-base with an already published REF. Every commit's message, identities and tree are checked, so deleting a private file at the tip doesn't clear history.

Commit author and committer emails (rule `C3`) must be GitHub noreply addresses (`<id>+<login>@users.noreply.github.com`, `<login>@users.noreply.github.com`, or `<n>+<name>[bot]@users.noreply.github.com` for bots); `noreply@github.com` is allowed for the committer field only (GitHub web-flow and merge-queue commits). Refusals name the commit and field (`commit-N-author` or `commit-N-committer`), never the email address.

The contract's `bad` blocks are skipped only at `contracts/open-development.v1.md`. The release candidate's D2 scan stages each archive's runtime at `<target>/runtime/` and passes `--runtime-root <target>` for each target, so the contract shipped at exactly `<target>/runtime/contracts/open-development.v1.md` gets the same rule; every other file, and every other path ending in that name, is scanned as before. `--runtime-root` needs `--tree`, applies only to it, and takes one plain path segment.

Workflows are read as a safe YAML subset; anything it doesn't recognise refuses, and every job needs an allowlisted runner.
Expand Down
8 changes: 6 additions & 2 deletions tools/privacy-check/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
ABBREVIATION = re.compile(r'\b(?:e\.g|i\.e|etc|vs|cf)\.', re.IGNORECASE)
SENTENCE_END = re.compile(r'[.!?](?=\s|$)')
COMMENT = re.compile(r'^\s*(?:#+|//+|/?\*+|>+|--)?\s*')
COMMIT_EMAIL = re.compile(r'(?:[1-9][0-9]*\+[A-Za-z0-9][A-Za-z0-9-]*|[A-Za-z0-9][A-Za-z0-9-]*)@users\.noreply\.github\.com|noreply@github\.com')
COMMIT_EMAIL = re.compile(r'(?:[1-9][0-9]*\+[A-Za-z0-9][A-Za-z0-9-]*(?:\[bot\])?|[A-Za-z0-9][A-Za-z0-9-]*)@users\.noreply\.github\.com')


class Unreadable(Exception):
Expand Down Expand Up @@ -215,6 +215,10 @@ def allowed_email(value):
(domain == 'github.com' and local in {'noreply', 'git', 'user', 'pass'}))


def allowed_commit_email(role, value):
return bool(COMMIT_EMAIL.fullmatch(value)) or (role == 'committer' and value == 'noreply@github.com')


def git_environment():
env = {k: v for k, v in os.environ.items() if not k.startswith('GIT_')}
env.update(GIT_NO_REPLACE_OBJECTS='1', GIT_NO_LAZY_FETCH='1', GIT_TERMINAL_PROMPT='0')
Expand Down Expand Up @@ -313,7 +317,7 @@ def history(checker, repo, base, head, upstream=None):
checker.refuse('C3', f'commit-{index}-{role}')
continue
email = re.fullmatch(r'.* <([^<>]*)> [0-9]+ [+-][0-9]{4}', rows[0])
if not email or not COMMIT_EMAIL.fullmatch(email[1]):
if not email or not allowed_commit_email(role, email[1]):
checker.refuse('C3', f'commit-{index}-{role}')
return hashes

Expand Down
39 changes: 34 additions & 5 deletions tools/privacy-check/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ def history(self, rule=None, base=None):
self.assertEqual(rc, 1 if rule else 0, out.getvalue())
if rule:
self.assertIn(rule + ' ', out.getvalue())
return out.getvalue()

def scan_git(self, *args):
children, start = [], subprocess.Popen
Expand Down Expand Up @@ -531,8 +532,16 @@ def timed_out(timeout=None):

def test_clean_history_and_commit_emails(self):
self.make_repo()
for email in (PRIVATE_MAIL, 'robin@users.noreply.github.com', 'noreply@github.com'):
self.git('commit', '--allow-empty', '-qm', 'clean', GIT_AUTHOR_EMAIL=email, GIT_COMMITTER_EMAIL=email)
bot = '41898282+synthetic-bot[bot]@users.noreply.github.com'
for author, committer in (
(PRIVATE_MAIL, PRIVATE_MAIL),
('robin@users.noreply.github.com', 'robin@users.noreply.github.com'),
(bot, bot),
(PRIVATE_MAIL, 'noreply@github.com'),
(bot, 'noreply@github.com'),
):
self.git('commit', '--allow-empty', '-qm', 'clean',
GIT_AUTHOR_EMAIL=author, GIT_COMMITTER_EMAIL=committer)
self.history()
self.verdict(self.call('--repo', self.repo, '--base', self.anchor, '--head', 'HEAD'), 'C1')

Expand All @@ -546,11 +555,31 @@ def test_bad_intermediate_commit_messages(self):

def test_bad_author_or_committer(self):
self.make_repo()
for key in ('GIT_AUTHOR_EMAIL', 'GIT_COMMITTER_EMAIL'):
for email in (BAD_MAIL, 'robin@example.com', 'git@github.com', '@users.noreply.github.com'):
cases = (
('GIT_AUTHOR_EMAIL', 'author', (
BAD_MAIL, 'robin@example.com', 'git@github.com', 'noreply@github.com',
'@users.noreply.github.com', 'synthetic-bot[bot]@users.noreply.github.com',
'0+synthetic-bot[bot]@users.noreply.github.com',
)),
('GIT_COMMITTER_EMAIL', 'committer', (
BAD_MAIL, 'robin@example.com', 'git@github.com',
'@users.noreply.github.com', 'synthetic-bot[bot]@users.noreply.github.com',
'0+synthetic-bot[bot]@users.noreply.github.com',
)),
)
for key, role, emails in cases:
for email in emails:
self.git('reset', '--soft', self.anchor)
self.git('commit', '--allow-empty', '-qm', 'clean', **{key: email})
self.history('C3')
out = self.history('C3')
self.assertIn(f'C3 commit-1-{role}:1', out)
self.assertNotIn(email, out)
self.git('reset', '--soft', self.anchor)
self.git('commit', '--allow-empty', '-qm', 'older personal commit',
GIT_AUTHOR_EMAIL=BAD_MAIL, GIT_COMMITTER_EMAIL=BAD_MAIL)
old_base = self.git('rev-parse', 'HEAD')
self.git('commit', '--allow-empty', '-qm', 'clean follow-up')
self.history(base=old_base)

def test_merged_private_ancestry_and_replace_objects(self):
self.make_repo()
Expand Down
Loading