From 9174985353fa19d9c0acc0952f124e0bf8122ec4 Mon Sep 17 00:00:00 2001 From: bntvllnt <32437578+bntvllnt@users.noreply.github.com> Date: Sun, 22 Nov 2026 16:18:51 +0100 Subject: [PATCH 1/2] ci: add Privacy Guard for new commits on this fork Copy the vllnt/skills Privacy Guard template and scope secret, email, and trailer checks to new commits. Full-history gitleaks and the working-tree denylist fail on upstream fixtures we do not control. --- .github/workflows/privacy-guard.yml | 83 ++++++++++++ .gitignore | 3 + .privacy-allowlist | 15 +++ .privacy-denylist | 42 +++++++ scripts/check-commit-emails.sh | 187 ++++++++++++++++++++++++++++ scripts/privacy-denylist.sh | 139 +++++++++++++++++++++ scripts/test-check-commit-emails.sh | 178 ++++++++++++++++++++++++++ scripts/test-privacy-denylist.sh | 176 ++++++++++++++++++++++++++ 8 files changed, 823 insertions(+) create mode 100644 .github/workflows/privacy-guard.yml create mode 100644 .privacy-allowlist create mode 100644 .privacy-denylist create mode 100755 scripts/check-commit-emails.sh create mode 100755 scripts/privacy-denylist.sh create mode 100755 scripts/test-check-commit-emails.sh create mode 100755 scripts/test-privacy-denylist.sh diff --git a/.github/workflows/privacy-guard.yml b/.github/workflows/privacy-guard.yml new file mode 100644 index 00000000000..d4688b3b16c --- /dev/null +++ b/.github/workflows/privacy-guard.yml @@ -0,0 +1,83 @@ +# Privacy Guard for a public fork of an upstream we do not control. +# Required status check name: "Privacy Guard". +# +# Copied from vllnt/skills references/capabilities/release-readiness/templates/privacy-guard.yml +# and scoped: full-history gitleaks and the working-tree denylist fail on +# upstream fixtures and test data (they are not in our control). This job +# still runs the template's tests, gitleaks over the new-commit range, and +# check-commit-emails.sh over the new-commit range (PR or pushed range). +# Do not print secret or personal values in logs. + +name: Privacy Guard + +on: + push: + pull_request: + +permissions: + contents: read + +concurrency: + group: privacy-guard-${{ github.head_ref || github.ref }} + cancel-in-progress: true + +jobs: + privacy-guard: + name: Privacy Guard + runs-on: ubuntu-latest + env: + GITLEAKS_VERSION: "8.30.1" + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + persist-credentials: false + - name: Install gitleaks + run: | + set -euo pipefail + base="https://github.com/gitleaks/gitleaks/releases/download/v${GITLEAKS_VERSION}" + archive="gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz" + curl -sSfL -o "$RUNNER_TEMP/$archive" "$base/$archive" + curl -sSfL -o "$RUNNER_TEMP/checksums.txt" "$base/gitleaks_${GITLEAKS_VERSION}_checksums.txt" + (cd "$RUNNER_TEMP" && grep " ${archive}\$" checksums.txt | sha256sum -c -) + tar -xzf "$RUNNER_TEMP/$archive" -C "$RUNNER_TEMP" gitleaks + echo "$RUNNER_TEMP" >> "$GITHUB_PATH" + - name: Resolve new-commit range + id: range + env: + EVENT_NAME: ${{ github.event_name }} + PR_BASE: ${{ github.event.pull_request.base.sha }} + PR_HEAD: ${{ github.event.pull_request.head.sha }} + BEFORE: ${{ github.event.before }} + run: | + set -euo pipefail + # This repo is a public fork. The template default of --all on the + # default branch would scan upstream history we do not control. + if [[ "$EVENT_NAME" == "pull_request" ]]; then + RANGE="${PR_BASE}..${PR_HEAD}" + elif [[ "${BEFORE:-}" != "" && "$BEFORE" != 0000000000000000000000000000000000000000 ]]; then + RANGE="${BEFORE}..HEAD" + else + RANGE="HEAD" + fi + echo "range=$RANGE" >> "$GITHUB_OUTPUT" + echo "Using commit range $RANGE" + - name: Scan new commits for secrets + run: | + set -euo pipefail + range="${{ steps.range.outputs.range }}" + if [[ "$range" == "HEAD" ]]; then + git rev-list -n 1 HEAD >/dev/null + elif ! git rev-list "$range" | grep -q .; then + echo "No new commits in range; skipping gitleaks" + exit 0 + fi + gitleaks detect --source . --log-opts="$range" --redact --no-banner --exit-code 1 + - name: Test denylist guard + run: bash scripts/test-privacy-denylist.sh + - name: Test commit-metadata email check + run: bash scripts/test-check-commit-emails.sh + - name: Check commit emails and trailers + env: + PRIVACY_COMMIT_RANGE: ${{ steps.range.outputs.range }} + run: bash scripts/check-commit-emails.sh diff --git a/.gitignore b/.gitignore index 66ce7837b26..d7448120e3d 100644 --- a/.gitignore +++ b/.gitignore @@ -69,3 +69,6 @@ docker-compose.override.yml # Local LLM Wiki vault .llm-wiki + +# Private privacy-guard patterns (never commit) +.privacy-denylist.local diff --git a/.privacy-allowlist b/.privacy-allowlist new file mode 100644 index 00000000000..2e5836a949e --- /dev/null +++ b/.privacy-allowlist @@ -0,0 +1,15 @@ +# Regexes matched against "path:line:token" of each denylist hit. Keep entries narrow +# and anchor them: a token is allowed only if the whole token matches. + +# Addresses on reserved or noreply domains, and the SSH remote user +:[0-9]+:[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+\.(test|invalid|example)$ +:[0-9]+:[A-Za-z0-9._%+-]+@example\.(com|org|net)$ +:[0-9]+:[A-Za-z0-9._%+-]+@users\.noreply\.github\.com$ +:[0-9]+:noreply@github\.com$ +:[0-9]+:git@github\.com$ + +# CI runner home directories +:[0-9]+:.?/home/(runner|user)$ + +# Generic copywriting example, not a real figure +^(plugins/[a-z]+/skills/)?(workflows/)?build-landing-page/references/copywriting-formulas\.md:[0-9]+:\$10k MRR$ diff --git a/.privacy-denylist b/.privacy-denylist new file mode 100644 index 00000000000..e9cc6dadcb4 --- /dev/null +++ b/.privacy-denylist @@ -0,0 +1,42 @@ +# Structural privacy patterns (extended regex, case-insensitive). Generic only: +# never put names, clients, hosts, or credentials here; this file is public. +# Private terms go in the untracked .privacy-denylist.local or the +# PRIVACY_DENYLIST_EXTRA CI secret. See scripts/privacy-denylist.sh. + +# Tailnet hostnames and addresses (CGNAT range, IPv6 ULA) +[a-z0-9-]+\.ts\.net\b +\b100\.(6[4-9]|[7-9][0-9]|1[01][0-9]|12[0-7])\.[0-9]{1,3}\.[0-9]{1,3}\b +\bfd7a:115c:a1e0:[0-9a-f:]+ + +# Provider-assigned VPS hostnames (not the vendor name itself) +[a-z0-9-]+\.vps\.ovh\.(net|ca)\b +[a-z0-9.-]+\.your-server\.de\b +[a-z0-9-]+\.hetzner\.cloud\b + +# Private network addresses +\b10\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\b +\b192\.168\.[0-9]{1,3}\.[0-9]{1,3}\b +\b172\.(1[6-9]|2[0-9]|3[01])\.[0-9]{1,3}\.[0-9]{1,3}\b + +# Machine-specific home and editor store paths (a path root, not a URL segment) +(^|[^A-Za-z0-9_./-])/(home|Users)/[A-Za-z0-9._-]+ +[A-Za-z]:\\Users\\[A-Za-z0-9._-]+ +/cursor/stores + +# UUIDs (account, bot, and device ids) +\b[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\b + +# Email addresses; a version suffix such as pkg@1.2.3-canary.abc1234 is not one +[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}\b + +# Phone numbers: international, US-style grouped, French-style grouped, 00-prefixed +(^|[^0-9A-Za-z])\+[0-9]{1,3}[ .-]?[0-9]([ .-]?[0-9]){7,12}\b +\(?[0-9]{3}\)?[ .-][0-9]{3}[ .-][0-9]{4}\b +\b0[1-9]([ .-][0-9]{2}){4}\b +\b00[0-9]{10,13}\b + +# Revenue and pricing figures +\bMRR\b[^.]{0,20}[0-9] +\b(revenue|turnover|pricing)\b[^.]{0,24}[$€£][0-9] +[$€£][0-9][0-9,.]*[kKmM]?[ ]?(MRR|ARR)\b +\b[0-9][0-9,.]*[kKmM]?[ ]?(€|EUR\b|USD\b) diff --git a/scripts/check-commit-emails.sh b/scripts/check-commit-emails.sh new file mode 100755 index 00000000000..e3897ac260d --- /dev/null +++ b/scripts/check-commit-emails.sh @@ -0,0 +1,187 @@ +#!/usr/bin/env bash +# +# check-commit-emails.sh — fail when a commit in the scan range uses a +# disallowed author, committer, Co-authored-by, or Signed-off-by email, +# or when commit metadata contains a private hostname or internal IP. +# +# Matched values are never printed. Findings are reported as +# +# only. Public CI logs are public. +# +# Range (first match wins): +# $PRIVACY_COMMIT_RANGE a git revision range, or the token --all +# --range | --all command-line flags +# otherwise --all +# +# Allowed emails (override with $ALLOWED_EMAIL_PATTERN): +# *@users.noreply.github.com and noreply@github.com +# +# Exit codes: 0 clean, 1 finding, 2 misuse. + +set -u + +cd "$(git rev-parse --show-toplevel)" || exit 2 + +ALLOWED_EMAIL_PATTERN="${ALLOWED_EMAIL_PATTERN:-(@users\.noreply\.github\.com|^noreply@github\.com)$}" + +# Hostname and address patterns, assembled from fragments so this file does +# not itself match a tree denylist. Keep them generic: no personal names. +TS_NET='[a-z0-9-]+\.ts''\.net\b' +OVH_VPS='[a-z0-9-]+\.vps\.ovh''\.net\b' +OVH_VPS_CA='[a-z0-9-]+\.vps\.ovh''\.ca\b' +HETZNER_DED='[a-z0-9.-]+\.your-server''\.de\b' +HETZNER_CLOUD='[a-z0-9-]+\.hetzner''\.cloud\b' +# Tailnet CGNAT (100.64/10) and RFC1918 +CGNAT='\b100\.(6[4-9]|[7-9][0-9]|1[01][0-9]|12[0-7])\.[0-9]{1,3}\.[0-9]{1,3}\b' +RFC10='\b10\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\b' +RFC192='\b192\.168\.[0-9]{1,3}\.[0-9]{1,3}\b' +RFC172='\b172\.(1[6-9]|2[0-9]|3[01])\.[0-9]{1,3}\.[0-9]{1,3}\b' + +HOSTNAME_PATTERN="${TS_NET}|${OVH_VPS}|${OVH_VPS_CA}|${HETZNER_DED}|${HETZNER_CLOUD}" +IP_PATTERN="${CGNAT}|${RFC10}|${RFC192}|${RFC172}" + +usage() { + echo "usage: $0 [--all] [--range ]" >&2 + exit 2 +} + +RANGE="${PRIVACY_COMMIT_RANGE:-}" +while [[ $# -gt 0 ]]; do + case "$1" in + --all) RANGE="--all"; shift ;; + --range) + [[ $# -ge 2 ]] || usage + RANGE="$2" + shift 2 + ;; + -h|--help) usage ;; + *) usage ;; + esac +done +[[ -n "$RANGE" ]] || RANGE="--all" + +# Validate the allowed-email pattern without printing it. +if ! printf 'a@users.noreply.github.com\n' | grep -qE "$ALLOWED_EMAIL_PATTERN"; then + echo "error: ALLOWED_EMAIL_PATTERN does not accept a GitHub noreply address" >&2 + exit 2 +fi +if ! printf 'noreply@github.com\n' | grep -qE "$ALLOWED_EMAIL_PATTERN"; then + echo "error: ALLOWED_EMAIL_PATTERN does not accept noreply@github.com" >&2 + exit 2 +fi + +# Resolve the commit list. An empty range (no new commits) is clean. +commits="$(mktemp)" +findings="$(mktemp)" +trap 'rm -f "$commits" "$findings"' EXIT + +if [[ "$RANGE" == "--all" ]]; then + if ! git rev-list --all > "$commits" 2>/dev/null; then + echo "error: could not list commits for --all" >&2 + exit 2 + fi +else + if ! git rev-list "$RANGE" > "$commits" 2>/dev/null; then + echo "error: invalid commit range" >&2 + exit 2 + fi +fi + +if [[ ! -s "$commits" ]]; then + echo "OK commit metadata: no commits in range" + exit 0 +fi + +# classify_email -> category (or empty if allowed) +classify_email() { + local addr="$1" + [[ -n "$addr" ]] || return 0 + if printf '%s\n' "$addr" | grep -qE "$ALLOWED_EMAIL_PATTERN"; then + return 0 + fi + if printf '%s\n' "$addr" | grep -qiE "$HOSTNAME_PATTERN"; then + echo "private-hostname" + return 0 + fi + if printf '%s\n' "$addr" | grep -qiE "$IP_PATTERN"; then + echo "private-ip" + return 0 + fi + echo "disallowed-email" +} + +# classify_text -> category (or empty) +classify_text() { + local text="$1" + [[ -n "$text" ]] || return 0 + if printf '%s\n' "$text" | grep -qiE "$HOSTNAME_PATTERN"; then + echo "private-hostname" + return 0 + fi + if printf '%s\n' "$text" | grep -qiE "$IP_PATTERN"; then + echo "private-ip" + return 0 + fi +} + +# extract_trailer_email — Co-authored-by / Signed-off-by "Name " +extract_trailer_email() { + local line="$1" addr + addr="$(printf '%s\n' "$line" | sed -n 's/.*<\([^>]*\)>.*/\1/p')" + printf '%s\n' "$addr" +} + +while IFS= read -r sha || [[ -n "$sha" ]]; do + [[ -n "$sha" ]] || continue + short="$(git rev-parse --short "$sha")" + author="$(git log -1 --format='%ae' "$sha")" + committer="$(git log -1 --format='%ce' "$sha")" + subject="$(git log -1 --format='%s' "$sha")" + body="$(git log -1 --format='%b' "$sha")" + + catg="$(classify_email "$author")" + [[ -n "$catg" ]] && printf '%s\tauthor\t%s\n' "$short" "$catg" >> "$findings" + catg="$(classify_email "$committer")" + [[ -n "$catg" ]] && printf '%s\tcommitter\t%s\n' "$short" "$catg" >> "$findings" + + # Trailers only (unfolded). Do not treat the whole body as trailers. + trailers="$(git log -1 --format='%(trailers:only,unfold)' "$sha")" + while IFS= read -r tline || [[ -n "$tline" ]]; do + [[ -n "$tline" ]] || continue + key="$(printf '%s\n' "$tline" | sed -n 's/^\([^:]*\):.*/\1/p' | tr '[:upper:]' '[:lower:]')" + case "$key" in + co-authored-by|signed-off-by) + addr="$(extract_trailer_email "$tline")" + catg="$(classify_email "$addr")" + field="Co-authored-by" + [[ "$key" == "signed-off-by" ]] && field="Signed-off-by" + [[ -n "$catg" ]] && printf '%s\t%s\t%s\n' "$short" "$field" "$catg" >> "$findings" + ;; + esac + done <<< "$trailers" + + # Subject and body (including non-trailer text) for hostnames and internal IPs. + # Email addresses in the message body that are not trailers are not classified + # here; author/committer/trailer checks cover the metadata leak path. + catg="$(classify_text "$subject")" + [[ -n "$catg" ]] && printf '%s\tmessage\t%s\n' "$short" "$catg" >> "$findings" + # Skip re-reporting the same category already found in the subject. + body_catg="$(classify_text "$body")" + if [[ -n "$body_catg" && "$body_catg" != "$catg" ]]; then + printf '%s\tmessage\t%s\n' "$short" "$body_catg" >> "$findings" + elif [[ -n "$body_catg" && -z "$catg" ]]; then + printf '%s\tmessage\t%s\n' "$short" "$body_catg" >> "$findings" + fi +done < "$commits" + +if [[ -s "$findings" ]]; then + count="$(wc -l < "$findings" | tr -d ' ')" + echo "FAIL commit metadata: $count finding(s); values withheld" + # field may contain a hyphen; columns are tab-separated + sort -u "$findings" | awk -F '\t' '{printf " %s %s %s\n", $1, $2, $3}' + exit 1 +fi + +n="$(wc -l < "$commits" | tr -d ' ')" +echo "OK commit metadata: $n commit(s) in range, no findings" +exit 0 diff --git a/scripts/privacy-denylist.sh b/scripts/privacy-denylist.sh new file mode 100755 index 00000000000..fc5f6580f99 --- /dev/null +++ b/scripts/privacy-denylist.sh @@ -0,0 +1,139 @@ +#!/usr/bin/env bash +# +# privacy-denylist.sh — fail when a tracked file matches a denylist pattern +# outside the allowlist. +# +# Patterns (extended regex, one per line, '#' comments; matched case-insensitively): +# .privacy-denylist required, tracked, structural patterns only +# .privacy-denylist.local optional, untracked, for names that must stay private +# $PRIVACY_DENYLIST_EXTRA optional, newline-separated; set it from a CI secret +# Allowlist (.privacy-allowlist): regexes matched against "path:line:token" for each +# matched token, so an allowed token never hides another match on the same line. +# +# Matched content and pattern text are never printed: CI logs of a public +# repository are public. +# +# Limits: only tracked files at the checked-out revision are scanned, not the +# commits of a pull request (gitleaks covers secret-shaped data in all history). +# UTF-16 text is not matched, and the allowlist file itself is not scanned. +# +# Exit codes: 0 clean, 1 match found, 2 misuse or invalid pattern. + +set -u + +cd "$(git rev-parse --show-toplevel)" || exit 2 + +DENY=.privacy-denylist +ALLOW=.privacy-allowlist +SELF=scripts/privacy-denylist.sh + +tracked="$(mktemp)" +extra="$(mktemp)" +local_raw="$(mktemp)" +extra_raw="$(mktemp)" +patterns="$(mktemp)" +allow_patterns="$(mktemp)" +hits="$(mktemp)" +kept="$(mktemp)" +probe="$(mktemp -d)" +trap 'rm -f "$tracked" "$extra" "$local_raw" "$extra_raw" "$patterns" "$allow_patterns" "$hits" "$kept"; rm -rf "$probe"' EXIT +printf '\n' > "$probe/empty" +printf 'a b\n' > "$probe/text" + +strip() { tr -d '\r' | sed -E '/^[[:space:]]*(#|$)/d'; } +# lines : the file with a guaranteed final newline. +lines() { cat "$1"; printf '\n'; } + +# Probes run a pattern with the engine and flags that later use it: git grep -iE for +# the denylist scan, grep -E for the allowlist filter. The two dialects differ. +# deny_probe/allow_probe +deny_probe() { (cd "$probe" && git grep --no-index -h -iE "$1" -e "$2" -- "$3" 2> /dev/null); } +allow_probe() { grep -E "$1" -e "$2" -- "$probe/$3" 2> /dev/null; } + +# A backslash before a letter or 0, other than \b \B \s \S \w \W, is a PCRE-style +# escape (\d, \x41, \Q, \p{L}) that extended regex silently misreads. +UNSUPPORTED_ESCAPE='(^|[^\])(\\\\)*\\[AC-RT-VX-Zac-rt-vx-z0]' + +# valid_regexes : every pattern line must compile with its +# engine and must not match the empty string. Errors name the source and line only. +valid_regexes() { + local file="$1" source="$2" probe_with="$3" n=0 line status + while IFS= read -r line || [[ -n "$line" ]]; do + n=$((n + 1)) + line="${line//$'\r'/}" + [[ "$line" =~ ^[[:space:]]*(#|$) ]] && continue + if [[ "$line" =~ $UNSUPPORTED_ESCAPE ]]; then + echo "error: $source pattern line $n uses an escape extended regex does not support" >&2 + return 1 + fi + "$probe_with" -q "$line" empty + status=$? + if (( status > 1 )); then + echo "error: $source pattern line $n is not a valid regex" >&2 + return 1 + fi + if (( status == 0 )); then + echo "error: $source pattern line $n matches the empty string" >&2 + return 1 + fi + # Zero-width patterns (\b, ^, $) match inside real text but report nothing. + if [[ -z "$("$probe_with" -o "$line" text)" ]] && "$probe_with" -q "$line" text; then + echo "error: $source pattern line $n is zero-width" >&2 + return 1 + fi + done < "$file" +} + +if [[ ! -f "$DENY" ]]; then + echo "error: $DENY is required" >&2 + exit 2 +fi +[[ -f "$DENY.local" ]] && cat "$DENY.local" > "$local_raw" +[[ -n "${PRIVACY_DENYLIST_EXTRA:-}" ]] && printf '%s\n' "$PRIVACY_DENYLIST_EXTRA" > "$extra_raw" +lines "$DENY" | strip > "$tracked" +{ lines "$local_raw"; lines "$extra_raw"; } | strip > "$extra" +cat "$tracked" "$extra" > "$patterns" +[[ -f "$ALLOW" ]] && lines "$ALLOW" | strip > "$allow_patterns" + +if [[ ! -s "$tracked" ]]; then + echo "error: $DENY has no patterns" >&2 + exit 2 +fi +valid_regexes "$DENY" "tracked" deny_probe || exit 2 +valid_regexes "$local_raw" "local" deny_probe || exit 2 +valid_regexes "$extra_raw" "extra" deny_probe || exit 2 +[[ -f "$ALLOW" ]] && { valid_regexes "$ALLOW" "allowlist" allow_probe || exit 2; } +if [[ -s "$allow_patterns" ]] && [[ -z "$(printf '%s\n' 'zz/canary.md:1:canary.ts''.net' | grep -avEf "$allow_patterns")" ]]; then + echo "error: allowlist is too broad; it would hide an obvious match" >&2 + exit 2 +fi + +# -a scans binary files as text; -o reports each matched token on its own line. +git grep -naoiE -f "$patterns" -- . ":(exclude)$DENY" ":(exclude)$ALLOW" ":(exclude)$SELF" > "$hits" 2> /dev/null +status=$? +if (( status > 1 )); then + echo "error: git grep failed" >&2 + exit 2 +fi + +if [[ -s "$allow_patterns" ]]; then + grep -avEf "$allow_patterns" "$hits" > "$kept" + status=$? + if (( status > 1 )); then + echo "error: allowlist filtering failed" >&2 + exit 2 + fi + mv "$kept" "$hits" +fi + +if [[ -s "$hits" ]]; then + echo "FAIL privacy denylist: $(wc -l < "$hits" | tr -d ' ') match(es); content withheld" + cut -d: -f1,2 "$hits" | sort -u | sed 's/^/ /' + exit 1 +fi + +extra_count="$(wc -l < "$extra" | tr -d ' ')" +if [[ "${CI:-}" == "true" && "$extra_count" == "0" ]]; then + echo "::warning title=Privacy guard::No private patterns loaded; only the tracked structural patterns were checked." +fi +echo "OK privacy denylist: no matches ($(wc -l < "$tracked" | tr -d ' ') tracked + $extra_count private patterns)" diff --git a/scripts/test-check-commit-emails.sh b/scripts/test-check-commit-emails.sh new file mode 100755 index 00000000000..046e815e281 --- /dev/null +++ b/scripts/test-check-commit-emails.sh @@ -0,0 +1,178 @@ +#!/usr/bin/env bash +# +# test-check-commit-emails.sh — success and failure paths of +# check-commit-emails.sh in a throwaway repository. Fixtures are assembled +# from fragments so this file never matches a tree denylist. + +set -u + +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +REPO="$(mktemp -d)" +trap 'rm -rf "$REPO"' EXIT + +mkdir -p "$REPO/scripts" +cp "$ROOT/scripts/check-commit-emails.sh" "$REPO/scripts/" +chmod +x "$REPO/scripts/check-commit-emails.sh" + +git -C "$REPO" init -q +git -C "$REPO" config user.email "123+tester@users.noreply.github.com" +git -C "$REPO" config user.name tester + +failures=0 +LAST_OUTPUT="" +LAST_STATUS=0 + +# Fragmented fixtures (adjacent quoted strings). +ICLOUD_ADDR="someone@""icloud.com" +OVH_HOST="vps-abc123fe"".vps.ovh.net" +OVH_EMAIL="ubuntu@${OVH_HOST}" +TS_HOST="box.example-net"".ts.net" +PRIV_IP="192.168"."0.42" +NOREPLY="123+tester@users.noreply.github.com" +WEB_FLOW="noreply@github.com" + +commit() { + # commit [VAR=value ...] — runs in $REPO + local message="$1"; shift + printf 'x\n' >> "$REPO/doc.md" + git -C "$REPO" add doc.md + (cd "$REPO" && env "$@" git commit -q -m "$message") +} + +run() { + local name="$1" expected="$2"; shift 2 + local envvars=() args=() + while [[ $# -gt 0 ]]; do + case "$1" in + --all) + args+=("$1"); shift + ;; + --range) + args+=("$1" "$2"); shift 2 + ;; + *=*) + envvars+=("$1"); shift + ;; + *) + args+=("$1"); shift + ;; + esac + done + LAST_OUTPUT="$(cd "$REPO" && env "${envvars[@]}" bash scripts/check-commit-emails.sh "${args[@]}" 2>&1)" + LAST_STATUS=$? + if [[ "$LAST_STATUS" != "$expected" ]]; then + printf 'FAIL %s: expected exit %s, got %s\n%s\n' "$name" "$expected" "$LAST_STATUS" "$LAST_OUTPUT" >&2 + failures=$((failures + 1)) + return 1 + fi + printf 'OK %s\n' "$name" + return 0 +} + +refute() { + local name="$1" text="$2" + if grep -qF -- "$text" <<< "$LAST_OUTPUT"; then + printf 'FAIL %s: output leaked %s\n%s\n' "$name" "" "$LAST_OUTPUT" >&2 + failures=$((failures + 1)) + fi +} + +expect() { + local name="$1" text="$2" + if ! grep -qE -- "$text" <<< "$LAST_OUTPUT"; then + printf 'FAIL %s: output missing %s\n%s\n' "$name" "$text" "$LAST_OUTPUT" >&2 + failures=$((failures + 1)) + fi +} + +# 1. Clean history of noreply commits passes (full history). +commit "clean base" +run "noreply history passes" 0 PRIVACY_COMMIT_RANGE=--all + +# 2. Personal author email fails; value withheld; sha and category reported. +commit "personal author" GIT_AUTHOR_EMAIL="$ICLOUD_ADDR" GIT_AUTHOR_NAME=someone +personal_sha="$(git -C "$REPO" rev-parse --short HEAD)" +run "personal author email fails" 1 PRIVACY_COMMIT_RANGE=--all +expect "reports author field" "author" +expect "reports disallowed-email" "disallowed-email" +expect "reports short sha" "$personal_sha" +refute "does not print personal address" "$ICLOUD_ADDR" +refute "does not print local-part" "someone@" + +# Reset to a clean line by going back? Keep going; later tests use ranges. + +# 3. Personal Co-authored-by trailer fails. +commit "$(printf 'add collaborator\n\nCo-authored-by: Someone <%s>\n' "$ICLOUD_ADDR")" +trailer_sha="$(git -C "$REPO" rev-parse --short HEAD)" +run "personal Co-authored-by fails" 1 --range "$trailer_sha^..$trailer_sha" +expect "reports Co-authored-by" "Co-authored-by" +expect "reports disallowed-email for trailer" "disallowed-email" +refute "trailer value withheld" "$ICLOUD_ADDR" + +# 4. Personal Signed-off-by trailer fails. +commit "$(printf 'signoff\n\nSigned-off-by: Someone <%s>\n' "$ICLOUD_ADDR")" +sign_sha="$(git -C "$REPO" rev-parse --short HEAD)" +run "personal Signed-off-by fails" 1 --range "$sign_sha^..$sign_sha" +expect "reports Signed-off-by" "Signed-off-by" +refute "signoff value withheld" "$ICLOUD_ADDR" + +# 5. Provider VPS hostname as author email fails as private-hostname. +commit "vps author" GIT_AUTHOR_EMAIL="$OVH_EMAIL" GIT_AUTHOR_NAME=ubuntu +vps_sha="$(git -C "$REPO" rev-parse --short HEAD)" +run "vps hostname author fails" 1 --range "$vps_sha^..$vps_sha" +expect "reports private-hostname" "private-hostname" +expect "reports author for vps" "author" +refute "vps hostname withheld" "$OVH_HOST" +refute "vps email withheld" "$OVH_EMAIL" + +# 6. web-flow committer (noreply@github.com) is allowed with a noreply author. +commit "web flow" GIT_COMMITTER_EMAIL="$WEB_FLOW" GIT_COMMITTER_NAME=GitHub +web_sha="$(git -C "$REPO" rev-parse --short HEAD)" +run "web-flow committer passes" 0 --range "$web_sha^..$web_sha" + +# 7. Commit message with a tailnet hostname fails; value withheld. +commit "mention $TS_HOST in the subject" +ts_sha="$(git -C "$REPO" rev-parse --short HEAD)" +run "tailnet hostname in message fails" 1 --range "$ts_sha^..$ts_sha" +expect "reports message field" "message" +expect "reports private-hostname for ts" "private-hostname" +refute "ts hostname withheld" "$TS_HOST" + +# 8. Commit message with an RFC1918 address fails. +commit "bind to $PRIV_IP" +ip_sha="$(git -C "$REPO" rev-parse --short HEAD)" +run "private ip in message fails" 1 --range "$ip_sha^..$ip_sha" +expect "reports private-ip" "private-ip" +refute "private ip withheld" "$PRIV_IP" + +# 9. A range that excludes dirty history passes. +# The first commit is clean; use that one only. +root="$(git -C "$REPO" rev-list --max-parents=0 HEAD)" +root_short="$(git -C "$REPO" rev-parse --short "$root")" +# Range of only the root commit: root^ is invalid; use root --not? Use +# git rev-list "$root" -1 via a one-commit range by SHA equality. +# --range does rev-list RANGE; a single sha lists that commit and ancestors. +# Use the root..root (empty) plus we need only the root. Pass the root as +# a range by setting PRIVACY_COMMIT_RANGE to the root sha — rev-list +# lists the sha and all ancestors, which for root is just root. +run "range of only the clean root passes" 0 --range "$root" +expect "clean range ok line" "OK" + +# 10. Empty range is clean (range from HEAD to HEAD with two-dot is empty). +head_sha="$(git -C "$REPO" rev-parse HEAD)" +run "empty two-dot range passes" 0 --range "${head_sha}..${head_sha}" +expect "empty range message" "no commits in range" + +# 11. Invalid range is misuse. +run "invalid range exits 2" 2 --range "this-is-not-a-rev-xyz" + +# 12. Full history still fails (dirty commits exist). +run "full history with dirt fails" 1 --all +expect "full history fail line" "FAIL commit metadata" + +if [[ "$failures" -ne 0 ]]; then + echo "FAILED $failures test(s)" >&2 + exit 1 +fi +echo "All check-commit-emails tests passed." +exit 0 diff --git a/scripts/test-privacy-denylist.sh b/scripts/test-privacy-denylist.sh new file mode 100755 index 00000000000..c07478399a5 --- /dev/null +++ b/scripts/test-privacy-denylist.sh @@ -0,0 +1,176 @@ +#!/usr/bin/env bash +# +# test-privacy-denylist.sh — success and failure paths of privacy-denylist.sh +# in a throwaway repository. Fixtures are assembled from fragments (adjacent +# quoted strings) so this file never matches the denylist itself. + +set -u + +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" +REPO="$(mktemp -d)" +trap 'rm -rf "$REPO"' EXIT + +mkdir -p "$REPO/scripts" +cp "$ROOT/scripts/privacy-denylist.sh" "$REPO/scripts/" +cp "$ROOT/.privacy-denylist" "$ROOT/.privacy-allowlist" "$REPO/" +git -C "$REPO" init -q +git -C "$REPO" config user.email test@example.invalid +git -C "$REPO" config user.name test + +failures=0 +LAST_OUTPUT="" + +# plant : write a one-line fixture. +plant() { printf '%s\n' "$1" > "$REPO/doc.md"; } + +# check [VAR=value ...] +check() { + local name="$1" expected="$2"; shift 2 + git -C "$REPO" add -A + local status + LAST_OUTPUT="$(cd "$REPO" && env "$@" bash scripts/privacy-denylist.sh 2>&1)" + status=$? + if [[ "$status" != "$expected" ]]; then + printf 'FAIL %s: expected exit %s, got %s\n%s\n' "$name" "$expected" "$status" "$LAST_OUTPUT" >&2 + failures=$((failures + 1)) + return + fi + printf 'OK %s\n' "$name" +} + +# refute : the last output must not contain the text. +refute() { + if grep -qF -- "$2" <<< "$LAST_OUTPUT"; then + printf 'FAIL %s\n' "$1" >&2 + failures=$((failures + 1)) + fi +} + +TAILNET="box.example-net.ts"".net" +OVH_VPS="vps-abc123fe"".vps.ovh.net" +HETZNER="node-1"".hetzner.cloud" +HETZNER_DED="static.12.34.56.clients.your-server"".de" + +plant "Plain documentation." +check "clean tree passes" 0 NOOP=1 + +plant "host: $TAILNET" +check "tailnet hostname fails" 1 NOOP=1 +grep -q 'doc.md:1' <<< "$LAST_OUTPUT" || { echo "FAIL hit location not reported" >&2; failures=$((failures + 1)); } +refute "matched content leaked to output" "example-net" + +plant "host: $OVH_VPS" +check "ovh vps hostname fails" 1 NOOP=1 +refute "ovh hostname leaked to output" "abc123fe" + +plant "host: $HETZNER" +check "hetzner cloud hostname fails" 1 NOOP=1 +refute "hetzner cloud leaked to output" "node-1" + +plant "host: $HETZNER_DED" +check "hetzner dedicated hostname fails" 1 NOOP=1 +refute "hetzner dedicated leaked to output" "your-server" + +plant "The host is an OVH VPS (provider name only)." +check "provider name without hostname passes" 0 NOOP=1 + +plant "id 123e4567-e89b-12d3-a456-4266""14174000" +check "uuid fails" 1 NOOP=1 + +plant "path /ho""me/someone/project/" +check "home path fails" 1 NOOP=1 +plant "HOME=/ho""me/someone" +check "home path without trailing slash fails" 1 NOOP=1 +plant "GET /api/us""ers/123/posts" +check "url route segment passes" 0 NOOP=1 +plant "cwd /ho""me/runner/work/x" +check "allowlisted runner home passes" 0 NOOP=1 + +plant "mail fixture@example.test" +check "reserved-domain address passes" 0 NOOP=1 +plant "mail someone@""company.io" +check "real-looking address fails" 1 NOOP=1 +plant "mail fixture@acme.test"".com" +check "reserved label inside a real domain fails" 1 NOOP=1 +plant "git clone git@github.com:owner/repo.git" +check "ssh remote user passes" 0 NOOP=1 +plant "pnpm add @scope/pkg@0.1.0-canary.bca5ab7" +check "package version pin passes" 0 NOOP=1 + +plant "call 415-555-""0132" +check "grouped phone number fails" 1 NOOP=1 +plant "MR""R is 12k" +check "bare revenue figure fails" 1 NOOP=1 + +plant "ssh admin@example.com $TAILNET" +check "allowed token does not hide another match on the line" 1 NOOP=1 + +printf '\0host %s\n' "$TAILNET" > "$REPO/doc.md" +check "binary file is scanned" 1 NOOP=1 +rm -f "$REPO/doc.md" +plant "Plain documentation." + +printf 'acme-widget appears here\n' >> "$REPO/doc.md" +check "extra pattern from environment fails" 1 'PRIVACY_DENYLIST_EXTRA=acme-widget' +check "extra pattern is not echoed" 1 'PRIVACY_DENYLIST_EXTRA=acme-widget' +refute "extra pattern text leaked to output" "acme-widget" +plant "Plain documentation." +check "extra pattern not present passes" 0 'PRIVACY_DENYLIST_EXTRA=acme-widget' +check "missing private patterns warn under CI" 0 CI=true +grep -q '::warning' <<< "$LAST_OUTPUT" || { echo "FAIL no warning when private patterns are absent in CI" >&2; failures=$((failures + 1)); } + +check "invalid private pattern is an error" 2 'PRIVACY_DENYLIST_EXTRA=Acme[Corp' +refute "invalid pattern text leaked to output" "Acme" +check "private pattern matching empty string is an error" 2 'PRIVACY_DENYLIST_EXTRA=acme|' + +# Constructs that grep -E accepts but git grep -E rejects or silently misreads. +for construct in '(?i)acme' 'acme(?=x)' 'acme(?!x)' '\p{L}acme' 'a{32768}' '\d{3}acme' '\x41acme' '\Qacme\E'; do + check "unsupported construct $construct is an error" 2 "PRIVACY_DENYLIST_EXTRA=$construct" + refute "unsupported construct $construct leaked to output" "acme" + refute "unsupported construct $construct passed validation" "git grep failed" +done +check "invalid private pattern reports its source and line" 2 "PRIVACY_DENYLIST_EXTRA=$(printf 'foo\n\n(?i)acme')" +grep -q 'extra pattern line 3' <<< "$LAST_OUTPUT" || { echo "FAIL invalid pattern source or line not reported" >&2; failures=$((failures + 1)); } +check "escaped backslash before a letter is a literal" 0 'PRIVACY_DENYLIST_EXTRA=acme\\d' +check "supported escapes and alternation pass" 0 'PRIVACY_DENYLIST_EXTRA=\bacme\s+(widget|gadget)\b' + +printf 'acme-widget appears here\n' >> "$REPO/doc.md" +check "crlf and blank private lines are normalized" 1 "PRIVACY_DENYLIST_EXTRA=$(printf 'foo\r\n\r\n\nacme-widget\r\n')" +plant "Plain documentation." + +cp "$REPO/.privacy-allowlist" "$REPO/allow.bak" +plant "host: $TAILNET" +printf '[unclosed\n' > "$REPO/.privacy-allowlist" +check "invalid allowlist regex is an error, not a pass" 2 NOOP=1 +printf 'zzz|\n' > "$REPO/.privacy-allowlist" +check "allowlist matching empty string is an error, not a pass" 2 NOOP=1 +cp "$REPO/allow.bak" "$REPO/.privacy-allowlist" + +plant "host: $TAILNET" +printf '.*' > "$REPO/.privacy-allowlist" +check "unterminated last allowlist line is still validated" 2 NOOP=1 +printf '^.+$\n' > "$REPO/.privacy-allowlist" +check "over-broad allowlist entry is an error, not a pass" 2 NOOP=1 +mv "$REPO/allow.bak" "$REPO/.privacy-allowlist" + +check "zero-width private pattern is an error" 2 'PRIVACY_DENYLIST_EXTRA=\b' +printf '\\b' > "$REPO/.privacy-denylist.local" +check "unterminated zero-width local pattern is an error" 2 NOOP=1 +rm "$REPO/.privacy-denylist.local" + +printf '\0/ho''me/someone\n' > "$REPO/doc.md" +check "nul-delimited token is not dropped by the allowlist filter" 1 NOOP=1 + +printf 'acme' > "$REPO/.privacy-denylist.local" +plant "only foo here" +check "local file and secret patterns stay separate" 1 PRIVACY_DENYLIST_EXTRA=foo +rm "$REPO/.privacy-denylist.local" + +rm "$REPO/.privacy-denylist" +check "missing denylist file is an error" 2 NOOP=1 + +if (( failures > 0 )); then + printf '%s failure(s)\n' "$failures" >&2 + exit 1 +fi +echo "OK privacy denylist tests passed" From 649a5cf610618309e4d9a2eb91a56e7f9fc1c5e3 Mon Sep 17 00:00:00 2001 From: bntvllnt <32437578+bntvllnt@users.noreply.github.com> Date: Sun, 22 Nov 2026 16:20:04 +0100 Subject: [PATCH 2/2] ci: do not pass a bare HEAD range to gitleaks `git log HEAD` walks every reachable commit, so the new-branch fallback scanned upstream history. Use origin/..HEAD instead. --- .github/workflows/privacy-guard.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/privacy-guard.yml b/.github/workflows/privacy-guard.yml index d4688b3b16c..cdfa7fd3de6 100644 --- a/.github/workflows/privacy-guard.yml +++ b/.github/workflows/privacy-guard.yml @@ -49,16 +49,19 @@ jobs: PR_BASE: ${{ github.event.pull_request.base.sha }} PR_HEAD: ${{ github.event.pull_request.head.sha }} BEFORE: ${{ github.event.before }} + DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} run: | set -euo pipefail # This repo is a public fork. The template default of --all on the # default branch would scan upstream history we do not control. + # Never use a bare HEAD for gitleaks --log-opts: `git log HEAD` + # walks every reachable commit. if [[ "$EVENT_NAME" == "pull_request" ]]; then RANGE="${PR_BASE}..${PR_HEAD}" elif [[ "${BEFORE:-}" != "" && "$BEFORE" != 0000000000000000000000000000000000000000 ]]; then RANGE="${BEFORE}..HEAD" else - RANGE="HEAD" + RANGE="origin/${DEFAULT_BRANCH}..HEAD" fi echo "range=$RANGE" >> "$GITHUB_OUTPUT" echo "Using commit range $RANGE"