diff --git a/infra/env/README.md b/infra/env/README.md index 0210427..0536f12 100644 --- a/infra/env/README.md +++ b/infra/env/README.md @@ -53,6 +53,8 @@ requires `CTID`, `HOSTNAME`, `IP`, `GAME` and `PUSH_TARGET`; `ROLE` defaults to Secrets. `PASS_KEY` holds the **name** of a `pass` entry, never a key. The Twitch app id/secret arrive as the systemd credential `twitch-app`, installed by -`infra/06-secrets.sh` from `pass` on the operator box; the OAuth tokens live in the +`infra/06-secrets.sh` from `pass` on the operator box, reading the two entry **names** from +`BRIDGE_ID_KEY` and `BRIDGE_SECRET_KEY` in the real env file (it skips `twitch-app` with a +warning when they are unset); the OAuth tokens live in the container as `/var/lib/flybridge/tokens.json`, mode 0600. `ROM_SHA256` is a digest, and the ROM it describes is never committed, copied into the repo, or shown on stream. diff --git a/infra/tests/pii-scan-test.sh b/infra/tests/pii-scan-test.sh index d8c7e03..672b6a0 100755 --- a/infra/tests/pii-scan-test.sh +++ b/infra/tests/pii-scan-test.sh @@ -168,5 +168,13 @@ git -C "$W" checkout -q main cp "$T/other-hook" "$W/.git/hooks/pre-push" expect 1 "install-hooks refuses to clobber a foreign hook" -- "$W/tools/install-hooks.sh" +# --- review-pii-guard N2/N3 (2026-09-29) ---------------------------------------------- +printf 'broken - (unclosed\n' > "$T/private/bad-patterns.txt" +expect 2 "an invalid private regex refuses to scan (never 'clean')" -- env FLY_PII_PATTERNS="$T/private/bad-patterns.txt" "$SCAN" --tree +printf '++ %s\n' "$LAN" > "$W/src/plusplus.txt" +git -C "$W" add -A && git -C "$W" commit -qm "a line that starts with ++" +expect 1 "an added line starting '++ ' is still scanned" -- "$SCAN" --range HEAD~1..HEAD +git -C "$W" rm -qf src/plusplus.txt && git -C "$W" commit -qm "drop it" + echo "===" if [ "$FAILS" -eq 0 ]; then echo "pii-scan-test: ALL PASSED"; else echo "pii-scan-test: ${FAILS} FAILED"; exit 1; fi diff --git a/tools/pii-scan.sh b/tools/pii-scan.sh index 3f2ba1f..ca5c095 100755 --- a/tools/pii-scan.sh +++ b/tools/pii-scan.sh @@ -73,7 +73,15 @@ trap 'rm -rf "$TMP"' EXIT # itself; they are not proper nouns. # -------------------------------------------------------------------------------------- NAMES=(); FLAGS=(); RES=(); KIND=() -pat() { NAMES+=("$1"); FLAGS+=("$2"); RES+=("$3"); KIND+=(re); } +# Every pattern is compiled once up front: grep exits 2 on a bad regex, and a scan that +# silently skipped a broken private pattern would report "clean" (fail open). +pat() { + local rc=0 f=-E + [ "$2" = -i ] && f=-iE + grep $f -e "$3" /dev/null 2>&1 || rc=$? + [ "$rc" -le 1 ] || die "pattern '$1' is not a valid extended regex; refusing to scan" + NAMES+=("$1"); FLAGS+=("$2"); RES+=("$3"); KIND+=(re) +} # name flags extended regex pat lan-address -i '\b192\.168\.[0-9]{1,3}\.[0-9]{1,3}\b|\b2600:[0-9a-f]' @@ -234,9 +242,10 @@ scan_range() { git -C "$REPO_ROOT" log -p --no-color --no-ext-diff --no-renames --unified=0 \ --format='PIISCAN-COMMIT %H' "$@" -- . ':!data' ':!package-lock.json' \ | awk -v corpus="$corpus" -v index_f="$index" ' - /^PIISCAN-COMMIT / { commit = $2; path = ""; next } - /^\+\+\+ / { path = substr($0, 5); sub(/^b\//, "", path); if (path == "/dev/null") path = ""; next } - /^@@ / { if (match($0, /\+[0-9]+/)) ln = substr($0, RSTART + 1, RLENGTH - 1) + 0; next } + /^PIISCAN-COMMIT / { commit = $2; path = ""; hdr = 0; next } + /^--- / { hdr = 1; next } + /^\+\+\+ / && hdr { path = substr($0, 5); sub(/^b\//, "", path); if (path == "/dev/null") path = ""; hdr = 0; next } + /^@@ / { hdr = 0; if (match($0, /\+[0-9]+/)) ln = substr($0, RSTART + 1, RLENGTH - 1) + 0; next } /^\+/ { if (path != "") { print substr($0, 2) > corpus; print commit "\t" path "\t" ln > index_f }; ln++; next } ' touch "$corpus" "$index"