|
| 1 | +#!/bin/sh |
| 2 | +# Refuses content that names things outside this repository: customer, employer or |
| 3 | +# infrastructure identifiers that have no business in a public history. |
| 4 | +# |
| 5 | +# Reads text on stdin. Exits non-zero and prints what matched. |
| 6 | +# |
| 7 | +# The list of real names lives in .git/leak-terms.txt, which is inside .git and therefore |
| 8 | +# never committed. That is deliberate: a deny-list of the words you are hiding, committed |
| 9 | +# to the repository, publishes exactly what it was meant to protect. |
| 10 | + |
| 11 | +terms_file="$(git rev-parse --git-dir)/leak-terms.txt" |
| 12 | + |
| 13 | +scan_input="$(mktemp)" |
| 14 | +cat > "$scan_input" |
| 15 | +trap 'rm -f "$scan_input"' EXIT |
| 16 | + |
| 17 | +# Literal matching is done in the shell rather than with "grep -qF", which aborts on some |
| 18 | +# Git for Windows builds and takes the whole check down with it, silently passing. |
| 19 | +lower="$(tr '[:upper:]' '[:lower:]' < "$scan_input")" |
| 20 | + |
| 21 | +found="" |
| 22 | + |
| 23 | +if [ -f "$terms_file" ]; then |
| 24 | + while IFS= read -r term || [ -n "$term" ]; do |
| 25 | + case "$term" in ''|\#*) continue ;; esac |
| 26 | + lterm="$(printf '%s' "$term" | tr '[:upper:]' '[:lower:]')" |
| 27 | + case "$lower" in |
| 28 | + *"$lterm"*) found="$found |
| 29 | + names a protected term: $term" ;; |
| 30 | + esac |
| 31 | + done < "$terms_file" |
| 32 | +fi |
| 33 | + |
| 34 | +# Built-in shapes, worth catching with no local list at all. Any noreply address is |
| 35 | +# excluded: git writes them into every trailer and they identify nobody. |
| 36 | +address="$(grep -oiE '[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}' "$scan_input" \ |
| 37 | + | grep -viE '(^|[.+-])noreply@|@noreply\.' | head -1)" |
| 38 | +[ -n "$address" ] && found="$found |
| 39 | + contains an email address: $address" |
| 40 | + |
| 41 | +if grep -qE '(gh[pousr]_[A-Za-z0-9]{16,}|sntrys_[A-Za-z0-9]{16,}|eyJ[A-Za-z0-9_-]{20,}\.)' "$scan_input"; then |
| 42 | + found="$found |
| 43 | + contains something shaped like a credential" |
| 44 | +fi |
| 45 | + |
| 46 | +if [ -n "$found" ]; then |
| 47 | + printf 'Refused: this would publish something internal.%s\n' "$found" |
| 48 | + printf '\nReword it, or add a deliberate exception to .git/leak-terms.txt\n' |
| 49 | + exit 1 |
| 50 | +fi |
| 51 | +exit 0 |
0 commit comments