Skip to content

Public text guard: a hashed denylist in the repository, and a step in CI - #483

Merged
nambok merged 1 commit into
mainfrom
text-guard-hashed
Nov 24, 2026
Merged

nambok merged 1 commit into
mainfrom
text-guard-hashed

Conversation

@nambok

@nambok nambok commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

The Public text guard no longer needs a secret or a required check. It reads a list of SHA-256 digests committed to the repository, and it runs as a step in CI's first job, so a PR with a leak goes red in CI.

Changes

  • .github/scripts/text_guard.py:
    • Hashed terms. A new rule, "denylisted term", fails on any term whose SHA-256 is in .github/text-guard.sha256. Text is normalized: lowercase, and every run of anything but letters and digits becomes one space. The guard hashes every run of 1 to 4 words of each line, and every 12-digit number (with or without dashes). The failure names only the line and the rule.
    • Adding terms. python3 .github/scripts/text_guard.py --hash-terms < terms.txt prints one digest per term, and never prints a term.
    • GUARD_DENYLIST is still read when it is set, as an optional extra.
    • Push events have no PR text, so the guard passes on them; on a push to main it does nothing.
  • .github/text-guard.sha256: the digest list, one per line, with a header saying how to add terms. It ships with the header only.
  • A new rule, "12-digit number", fails on any standalone 12-digit number, with or without dashes, apart from AWS's placeholder ids. Account ids are caught this way without being listed.
  • .github/workflows/ci.yml: the first job (Workflow security here, Lint & Build in the site repo) now checks out the full history and runs the guard's tests, then the guard, on every pull request push.
  • .github/workflows/text-guard.yml now runs only on edited, so an edit to the title or body is checked without rerunning CI.
  • .github/scripts/test_text_guard.py: tests for normalization, 1- to 4-word runs, parts and neighbours of a term that must not match, 12-digit numbers, the digest file's format, and a failure that prints no term. Every term is synthetic and is hashed inside the test.

Verification

  • The guard tests pass locally, along with the workflow checks and actionlint.
  • A test PR with a synthetic leak turned CI red at the guard step and was closed without merging.

The guard now fails on any term whose SHA-256 is in .github/text-guard.sha256.
Terms are normalized (lowercase, every run of other characters one space),
and the guard hashes every run of 1 to 4 words of each line it checks, and
every 12-digit number, so the file names no term. The failure says only the
line and "denylisted term". `text_guard.py --hash-terms` hashes a list read
from standard input. GUARD_DENYLIST stays as an optional extra. A new rule fails on any
standalone 12-digit number, apart from AWS's placeholder ids, so account
ids are caught without being listed.

CI's first job runs the guard on every push to a PR, so a PR whose title,
body, commits or docs additions carry an install's details goes red in CI.
The Public text guard workflow now runs only when the PR's text is edited.

Tests use synthetic terms hashed in the test itself.
@nambok
nambok merged commit d3cb55f into main Nov 24, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant