From 69f51413f2cbda11cda4d5af0e259ea1b0ba92d5 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Wed, 28 Oct 2026 21:11:33 -0500 Subject: [PATCH 1/4] fix(audit): refuse search errors instead of reporting a clean scan --- .github/workflows/ci.yml | 7 ++++ evidence/AUDIT-SCAN-ERRORS-20261029.md | 28 +++++++++++++++ tools/extract/.crumb | 19 ++++++++++ tools/extract/audit-error-selftest.sh | 50 ++++++++++++++++++++++++++ tools/extract/audit-scan.sh | 29 ++++++++++++--- tools/extract/audit-selftest.sh | 1 + 6 files changed, 129 insertions(+), 5 deletions(-) create mode 100644 evidence/AUDIT-SCAN-ERRORS-20261029.md create mode 100644 tools/extract/.crumb create mode 100644 tools/extract/audit-error-selftest.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3c74c8c7..4198c9b5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,6 +11,13 @@ on: permissions: contents: read jobs: + audit-scanner: + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + - name: Scanner detections and error refusal controls + run: bash tools/extract/audit-selftest.sh host-tests: runs-on: ubuntu-24.04-arm timeout-minutes: 40 diff --git a/evidence/AUDIT-SCAN-ERRORS-20261029.md b/evidence/AUDIT-SCAN-ERRORS-20261029.md new file mode 100644 index 00000000..cb410113 --- /dev/null +++ b/evidence/AUDIT-SCAN-ERRORS-20261029.md @@ -0,0 +1,28 @@ + +# Scanner error refusal regression + +Base: b348277e4383ab1f37f45bb702ea7d4fb4363782. Linux host-only. +No repository-wide clean-audit conclusion is established by this fixture. +Issue #89 remains the owner of complete audit execution and independent review. + +`bash tools/extract/audit-error-selftest.sh` against original audit-scan.sh: +exit 1, `grep phase -naP returned 0, expected 2`. This is a reproduced false +success from an injected search-tool error, not evidence about real secrets. + +`bash tools/extract/audit-selftest.sh` against the fixed scanner: exit 0. +The original 17 planted detections still pass. Added controls verify: +- injected errors in raw-secret, raw-private, message-secret and message-private scans return 2; +- invalid secret/private patterns return 2; +- corrupted compressed content returns 2 and remains listed as unscanned; +- clean synthetic history returns 0; +- a synthetic secret in a filename containing the former formatting delimiter returns 1 and is retained. + +The fix distinguishes grep status 1 (no matches) from errors, writes matches +before formatting them, and uses literal output prefixes. Formatting pipeline +errors remain subject to pipefail. Binary-count pipeline failures are also +checked before classification. A dedicated CI job runs both scanner test sets. + +Tested source identities: +3dfe636aa78689dcfe443e68205b49c1230f94edd2d1566f1eb5526bb4f86e2c tools/extract/audit-scan.sh +4596ffdcb2f6171bc235f6855ccb0064d6827a030297e6a4983337802b61820a tools/extract/audit-selftest.sh +30f8866924b793e1925d40b90157ee0fa1c6b1985de9c0ebcec5922c89d81e59 tools/extract/audit-error-selftest.sh diff --git a/tools/extract/.crumb b/tools/extract/.crumb new file mode 100644 index 00000000..d322ce18 --- /dev/null +++ b/tools/extract/.crumb @@ -0,0 +1,19 @@ +{ + "extensions": { + "generated": { + "children": [], + "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "compiled_at": "2026-10-29T02:11:33Z", + "compiler": "crumb-compile/1", + "digest": "sha256:8abf13df02f5aa5fe48c676258503a3dd68503b7757678a5eed60a4a6990bfc8", + "evidence_files": 0, + "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "files": 30, + "generated_at_commit": "b348277e4383ab1f37f45bb702ea7d4fb4363782", + "source_tree": "sha256:19039ce56097185e1d79d17be4d8c2e75554bcb5218663794a47bb146a9dccc7" + } + }, + "name": "extract", + "purpose": "Publication scanner and extraction verification tools; scan errors must never establish clean results.", + "schema_version": "1.0.0" +} diff --git a/tools/extract/audit-error-selftest.sh b/tools/extract/audit-error-selftest.sh new file mode 100644 index 00000000..856098bb --- /dev/null +++ b/tools/extract/audit-error-selftest.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env bash +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +set -euo pipefail +here=$(cd "$(dirname "$0")" && pwd) +t=$(mktemp -d) +trap 'rm -rf "$t"' EXIT +mkdir -p "$t/scanner" "$t/bin" "$t/repo" +cp "$here/audit-scan.sh" "$t/scanner/audit-scan.sh" +printf '%s\n' SYNTHETIC_ONLY > "$t/scanner/rules-secrets.txt" +printf '%s\n' PRIVATE_ONLY > "$t/scanner/rules-private.txt" +git -C "$t/repo" init -q +git -C "$t/repo" config user.name test +git -C "$t/repo" config user.email test@example.invalid +printf '%s\n' benign > "$t/repo/input" +git -C "$t/repo" add input +git -C "$t/repo" commit -qm initial +real_grep=$(command -v grep) +printf '#!/bin/bash\nif [[ ${1-} == "${SCAN_FAIL_MODE-}" ]]; then exit 2; fi\nexec %q "$@"\n' "$real_grep" > "$t/bin/grep" +chmod +x "$t/bin/grep" +for phase in -naP -noaP -nP -noP; do + rc=0 + PATH="$t/bin:$PATH" SCAN_FAIL_MODE="$phase" bash "$t/scanner/audit-scan.sh" "$t/repo" "$t/out" > "$t/log" 2>&1 || rc=$? + if [[ $rc != 2 ]]; then + echo "ERROR SELFTEST FAIL: grep phase $phase returned $rc, expected 2" + exit 1 + fi +done +for rule in secrets private; do + cp "$t/scanner/rules-$rule.txt" "$t/rule.save" + printf '[\n' > "$t/scanner/rules-$rule.txt" + rc=0 + bash "$t/scanner/audit-scan.sh" "$t/repo" "$t/out" > "$t/log" 2>&1 || rc=$? + cp "$t/rule.save" "$t/scanner/rules-$rule.txt" + [[ $rc == 2 ]] || { echo "ERROR SELFTEST FAIL: invalid $rule regex returned $rc"; exit 1; } +done +bash "$t/scanner/audit-scan.sh" "$t/repo" "$t/out" > "$t/log" +printf '\037\213broken' > "$t/repo/corrupt.gz" +git -C "$t/repo" add . +git -C "$t/repo" commit -qm corrupt +rc=0 +bash "$t/scanner/audit-scan.sh" "$t/repo" "$t/out" > "$t/log" 2>&1 || rc=$? +[[ $rc == 2 && -s $t/out/unscanned.txt ]] || { echo 'ERROR SELFTEST FAIL: corrupt compression was not refused'; exit 1; } +printf '%s\n' SYNTHETIC_ONLY > "$t/repo/delimiter|file" +git -C "$t/repo" add . +git -C "$t/repo" commit -qm delimiter +rc=0 +bash "$t/scanner/audit-scan.sh" "$t/repo" "$t/out" > "$t/log" 2>&1 || rc=$? +[[ $rc == 1 ]] || { echo "ERROR SELFTEST FAIL: delimiter-path secret returned $rc"; exit 1; } +grep -F 'delimiter|file:' "$t/out/secrets.txt" > /dev/null +echo 'ERROR SELFTEST PASS: scan errors refuse; clean input and delimiter-path detection preserved' diff --git a/tools/extract/audit-scan.sh b/tools/extract/audit-scan.sh index ba0b926c..4822406f 100755 --- a/tools/extract/audit-scan.sh +++ b/tools/extract/audit-scan.sh @@ -36,9 +36,25 @@ awk 'NF>=2 {sha=$1; $1=""; sub(/^ /,""); if (!(sha in p)) p[sha]=$0} END {for (s : > "$out/compressed.txt"; : > "$out/unscanned.txt" # scan FILE LABEL: secret and private rules over the raw bytes (-a: a NUL byte # must not make grep skip the file or stop matching). +matches() { + local rc=0 + grep "$@" > "$tmp/matches" || rc=$? + if (( rc > 1 )); then + echo "AUDIT INCOMPLETE: grep failed with status $rc" >&2 + exit 2 + fi +} +prefix() { + local label=$1 line + while IFS= read -r line; do + printf '%s:%s\n' "$label" "$line" + done +} scan() { - grep -naP -e "$secret_re" "$1" 2>/dev/null | tr -d '\000' | cut -c1-200 | sed "s|^|$sha $2:|" >> "$out/secrets.txt" || true - grep -noaP -e "$private_re" "$1" 2>/dev/null | tr -d '\000' | sed "s|^|$2:|" >> "$out/private.txt" || true + matches -naP -e "$secret_re" "$1" + tr -d '\000' < "$tmp/matches" | cut -c1-200 | prefix "$sha $2" >> "$out/secrets.txt" + matches -noaP -e "$private_re" "$1" + tr -d '\000' < "$tmp/matches" | prefix "$2" >> "$out/private.txt" } mkdir -p "$tmp/b" nblob=0 @@ -50,7 +66,8 @@ while read -r sha type size; do # Binary = contains a NUL byte. Counted with tr, not grep -P '\x00': GNU # grep 3.11 under LC_ALL=C never matches NUL that way, which left this list # empty on every run before 2026-10-27 (CUDApp#89). - if [[ $(tr -dc '\000' < "$tmp/b/x" | wc -c) -gt 0 ]]; then + nul_bytes=$(tr -dc '\000' < "$tmp/b/x" | wc -c) + if [[ $nul_bytes -gt 0 ]]; then echo "$sha $size $path" >> "$out/binaries.txt" fi scan "$tmp/b/x" "$path" @@ -77,8 +94,10 @@ done < "$tmp/types" # commit and tag messages (and identities, for the record) git -C "$repo" log --all --format='%H%n%B' > "$tmp/msgs" git -C "$repo" for-each-ref refs/tags --format='%(objectname)%0a%(contents)' >> "$tmp/msgs" -grep -nP -e "$secret_re" "$tmp/msgs" | cut -c1-200 | sed 's|^|MSG:|' >> "$out/secrets.txt" || true -grep -noP -e "$private_re" "$tmp/msgs" | sed 's|^|MSG:|' >> "$out/private.txt" || true +matches -nP -e "$secret_re" "$tmp/msgs" +cut -c1-200 < "$tmp/matches" | prefix MSG >> "$out/secrets.txt" +matches -noP -e "$private_re" "$tmp/msgs" +prefix MSG < "$tmp/matches" >> "$out/private.txt" cp "$tmp/msgs" "$out/messages.txt" # private hits, grouped by the matched text (the reviewer reads this list) diff --git a/tools/extract/audit-selftest.sh b/tools/extract/audit-selftest.sh index 76e8e82f..a86cf516 100755 --- a/tools/extract/audit-selftest.sh +++ b/tools/extract/audit-selftest.sh @@ -44,3 +44,4 @@ if (( found < planted )); then echo "SELFTEST FAIL: planted $planted, found $fou if ! grep -q "^$binsha " "$t/out/binaries.txt"; then echo "SELFTEST FAIL: NUL-byte blob not listed in binaries.txt"; exit 1; fi if ! grep -q "leak.gz(gzip):" "$t/out/secrets.txt"; then echo "SELFTEST FAIL: secret inside gzip blob not found"; exit 1; fi echo "SELFTEST PASS: planted $planted (one in a deleted file's history, one in a commit message, one in a NUL-byte blob, one gzipped), found $found; binary listed" +bash "$here/audit-error-selftest.sh" From c67fc2772186b35b562d5067449fb3dc8997bc57 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Wed, 28 Oct 2026 21:12:18 -0500 Subject: [PATCH 2/4] fix(audit): open match output before interpreting grep status --- evidence/AUDIT-SCAN-FD-20261029.md | 13 +++++++++++++ tools/extract/.crumb | 8 ++++---- tools/extract/audit-scan.sh | 7 +++++-- 3 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 evidence/AUDIT-SCAN-FD-20261029.md diff --git a/evidence/AUDIT-SCAN-FD-20261029.md b/evidence/AUDIT-SCAN-FD-20261029.md new file mode 100644 index 00000000..72e0efdf --- /dev/null +++ b/evidence/AUDIT-SCAN-FD-20261029.md @@ -0,0 +1,13 @@ + +# Match-output open failure distinction + +Follow-up to source 69f51413. The scanner now opens its match-output descriptor +before invoking grep, so a shell output-redirection failure cannot be confused +with grep's no-match exit status. No detection pattern changes. + +`bash tools/extract/audit-selftest.sh` passes after this change, retaining the +original 17 detections and every error-refusal control described in +AUDIT-SCAN-ERRORS-20261029.md. The earlier receipt remains bound to its earlier +source, not relabeled. This is host scanner verification, not a clean-history +claim. Tested scanner SHA-256: +bc726f90851ba5e9a33939a7bf88b10c9424a0d0e3281562c9c925e089bd7bbf tools/extract/audit-scan.sh diff --git a/tools/extract/.crumb b/tools/extract/.crumb index d322ce18..d27ab677 100644 --- a/tools/extract/.crumb +++ b/tools/extract/.crumb @@ -3,14 +3,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-29T02:11:33Z", + "compiled_at": "2026-10-29T02:12:18Z", "compiler": "crumb-compile/1", - "digest": "sha256:8abf13df02f5aa5fe48c676258503a3dd68503b7757678a5eed60a4a6990bfc8", + "digest": "sha256:950b478b9a8dba335a0d898a1635d92638151e4a4459f9b37941e0589f4251b0", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 30, - "generated_at_commit": "b348277e4383ab1f37f45bb702ea7d4fb4363782", - "source_tree": "sha256:19039ce56097185e1d79d17be4d8c2e75554bcb5218663794a47bb146a9dccc7" + "generated_at_commit": "69f51413f2cbda11cda4d5af0e259ea1b0ba92d5", + "source_tree": "sha256:bd6caed5b94c0418e2ad264f7872289ae24d269c367382f5e6018f31344f8fdb" } }, "name": "extract", diff --git a/tools/extract/audit-scan.sh b/tools/extract/audit-scan.sh index 4822406f..a719cebf 100755 --- a/tools/extract/audit-scan.sh +++ b/tools/extract/audit-scan.sh @@ -37,8 +37,11 @@ awk 'NF>=2 {sha=$1; $1=""; sub(/^ /,""); if (!(sha in p)) p[sha]=$0} END {for (s # scan FILE LABEL: secret and private rules over the raw bytes (-a: a NUL byte # must not make grep skip the file or stop matching). matches() { - local rc=0 - grep "$@" > "$tmp/matches" || rc=$? + local rc=0 match_fd + # Open separately: a shell redirection failure must not look like grep's no-match status. + exec {match_fd}> "$tmp/matches" + grep "$@" >&"$match_fd" || rc=$? + exec {match_fd}>&- if (( rc > 1 )); then echo "AUDIT INCOMPLETE: grep failed with status $rc" >&2 exit 2 From b6e92a1b2f2bce8e65f85857e40f8a22bb48b22f Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Wed, 28 Oct 2026 21:13:06 -0500 Subject: [PATCH 3/4] test(audit): require refusal when match output cannot be opened --- evidence/AUDIT-SCAN-OUTPUT-20261029.md | 13 +++++++++++++ tools/extract/.crumb | 8 ++++---- tools/extract/audit-error-selftest.sh | 7 +++++++ tools/extract/audit-scan.sh | 5 ++++- 4 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 evidence/AUDIT-SCAN-OUTPUT-20261029.md diff --git a/evidence/AUDIT-SCAN-OUTPUT-20261029.md b/evidence/AUDIT-SCAN-OUTPUT-20261029.md new file mode 100644 index 00000000..bf15cc81 --- /dev/null +++ b/evidence/AUDIT-SCAN-OUTPUT-20261029.md @@ -0,0 +1,13 @@ + +# Output-open failure control + +Follow-up to c67fc277. The synthetic mktemp wrapper creates a directory where +match output must be opened. The scanner now reports incomplete and exits 2. +The complete audit-selftest exits 0 with original planted detections and all +error controls passing. This adds an executed output-open control to the +previously recorded search, regex, compression and filename controls. +No real repository-wide clean result is claimed. + +Tested source SHA-256: +5538f3ddab502e44e16b6dac5101c1ef27fe28fc72057416f6395444127b8a98 tools/extract/audit-scan.sh +289c1cb9ba451f861411cd9a7d8ff1c78e5993f2ba40008e9698882f0db9ec24 tools/extract/audit-error-selftest.sh diff --git a/tools/extract/.crumb b/tools/extract/.crumb index d27ab677..4024be03 100644 --- a/tools/extract/.crumb +++ b/tools/extract/.crumb @@ -3,14 +3,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-29T02:12:18Z", + "compiled_at": "2026-10-29T02:13:05Z", "compiler": "crumb-compile/1", - "digest": "sha256:950b478b9a8dba335a0d898a1635d92638151e4a4459f9b37941e0589f4251b0", + "digest": "sha256:d0c7122592333dfe6ea9a77efb7fa1722f69525ce0b4c1ef1fb774dd9c4da4dc", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 30, - "generated_at_commit": "69f51413f2cbda11cda4d5af0e259ea1b0ba92d5", - "source_tree": "sha256:bd6caed5b94c0418e2ad264f7872289ae24d269c367382f5e6018f31344f8fdb" + "generated_at_commit": "c67fc2772186b35b562d5067449fb3dc8997bc57", + "source_tree": "sha256:6e807561b32f039d7bc048885a7f8ce3a9e96f42945f35deee971c1eb2407d24" } }, "name": "extract", diff --git a/tools/extract/audit-error-selftest.sh b/tools/extract/audit-error-selftest.sh index 856098bb..68f2f4e0 100644 --- a/tools/extract/audit-error-selftest.sh +++ b/tools/extract/audit-error-selftest.sh @@ -25,6 +25,13 @@ for phase in -naP -noaP -nP -noP; do exit 1 fi done +mkdir "$t/openfailbin" +real_mktemp=$(command -v mktemp) +printf '#!/bin/bash\nset -e\np=$(%q "$@")\nmkdir "$p/matches"\nprintf "%%s\\n" "$p"\n' "$real_mktemp" > "$t/openfailbin/mktemp" +chmod +x "$t/openfailbin/mktemp" +rc=0 +PATH="$t/openfailbin:$PATH" bash "$t/scanner/audit-scan.sh" "$t/repo" "$t/out" > "$t/log" 2>&1 || rc=$? +[[ $rc == 2 ]] || { echo "ERROR SELFTEST FAIL: output-open error returned $rc"; exit 1; } for rule in secrets private; do cp "$t/scanner/rules-$rule.txt" "$t/rule.save" printf '[\n' > "$t/scanner/rules-$rule.txt" diff --git a/tools/extract/audit-scan.sh b/tools/extract/audit-scan.sh index a719cebf..8c23da4b 100755 --- a/tools/extract/audit-scan.sh +++ b/tools/extract/audit-scan.sh @@ -39,7 +39,10 @@ awk 'NF>=2 {sha=$1; $1=""; sub(/^ /,""); if (!(sha in p)) p[sha]=$0} END {for (s matches() { local rc=0 match_fd # Open separately: a shell redirection failure must not look like grep's no-match status. - exec {match_fd}> "$tmp/matches" + if ! exec {match_fd}> "$tmp/matches"; then + echo 'AUDIT INCOMPLETE: cannot open match output' >&2 + exit 2 + fi grep "$@" >&"$match_fd" || rc=$? exec {match_fd}>&- if (( rc > 1 )); then From 8f798a05f7c25dff991981ca414a4e180e423218 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Wed, 28 Oct 2026 21:13:20 -0500 Subject: [PATCH 4/4] ci: keep checkout credentials out of scanner fixtures --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4198c9b5..6131f66b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,6 +16,8 @@ jobs: timeout-minutes: 5 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - name: Scanner detections and error refusal controls run: bash tools/extract/audit-selftest.sh host-tests: