carlos / platform Public

gitleaks: allow source digests only on whole digest lines

The allowance took any 10 to 64 hex value in the census tests and the
design checklist, so a hex API key pasted into one of those files passed.
It now matches the whole line: a complete census entry, or a Go file's
path and digest in the checklist. The other allowances are exact values.

A digest cut by gitleaks' chunk boundary has its own pattern, because
gitleaks reports the whole chunk as the line for that finding.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev d944ac5745b9c7cd183c0c5b8345f15d54f42899 parent f801480
2 files changed, +34 −15
  • .amadan/README.md +3 −1
  • .gitleaks.toml +31 −14

CI passed — run details

diff --git a/.amadan/README.md b/.amadan/README.md
index d95bde406..4409aa995 100644
--- a/.amadan/README.md
+++ b/.amadan/README.md
@@ -159,7 +159,9 @@ values in the history would otherwise hold every branch red.
A finding fails the step. Remove the value, and rotate it if it was ever
real. A fake a test needs, or something that is not a value at all, is
allowed in `.gitleaks.toml` by its exact value, scoped to the files it
-belongs in where that matters, with the reason beside it. One trap is
+belongs in where that matters, with the reason beside it. Source digests
+are the one exception: they pass only where the whole line is a digest
+entry, in the files that hold them. One trap is
written at the top of that file: in `gitleaks dir`, an allowance that
names `paths` without `targetRules` skips those files entirely, whatever
its condition says.
diff --git a/.gitleaks.toml b/.gitleaks.toml
index 55e5030e8..60d996b34 100644
--- a/.gitleaks.toml
+++ b/.gitleaks.toml
@@ -3,8 +3,8 @@
# tree's tracked files with it; the Makefile says why not the history.
#
# Every allowance names its values, anchored, so a value that merely
-# contains one is still found; only the census digests go by their shape,
-# and only in their own files. Where a value only belongs in some files,
+# contains one is still found; only the source digests go by their shape:
+# the whole line must be a digest entry, in the files that hold them. Where a value only belongs in some files,
# the allowance is scoped to them (condition AND: a path and a value), so
# the same value anywhere else still fails the gate. Nothing is allowed by
# fingerprint in .gitleaksignore: a fingerprint names a commit, and this
@@ -22,22 +22,39 @@
[extend]
useDefault = true
-# sha256 digests the census pins: of a function's source
-# (internal/provision's *_census_test.go layers) and of the source files a
-# design checklist was written against. A hash of code that is itself in
-# this repository; generic-api-key matches it because the word before it
-# is "RecordKey", "recordKey" or a file name. Shorter than 64 too:
-# gitleaks reads a big file in chunks, and a digest a chunk boundary cuts
-# is reported as the part before the cut.
+# sha256 digests the census pins: of a function's source, in
+# internal/provision's *_census_test.go layers. A hash of code that is
+# itself in this repository; generic-api-key matches it because the field
+# before it names a record key. Matched against the whole line, so only a
+# complete census entry passes: a hex credential on any other line of these
+# files, an `api_key = "..."` above all, is still found.
+#
+# The second pattern is the same entry cut short. gitleaks reads a big file
+# in chunks, and in plan9_b8_census_test.go one boundary falls inside a
+# digest. For a finding on a chunk's unterminated last line, gitleaks hands
+# over the whole chunk as the "line", so this pattern holds only the chunk's
+# last line to the entry's shape. Older layers are frozen, so that boundary
+# does not move.
[[allowlists]]
-description = "census and checklist source digests"
+description = "census entries' source digests"
targetRules = ["generic-api-key"]
condition = "AND"
-paths = [
- '''^internal/provision/[^/]+_census_test\.go$''',
- '''^implementation/always-awake-consumers\.json$''',
+regexTarget = "line"
+paths = ['''^internal/provision/[^/]+_census_test\.go$''']
+regexes = [
+ '''^\s*(?:censusEntry)?\{"[A-Za-z0-9_./-]+\.go", "[^"\n]+", "[a-z-]+", "(?:key|sel):[A-Za-z]+(?:,(?:key|sel):[A-Za-z]+)*", "[0-9a-f]{64}"\},\s*$''',
+ '''\n[ \t]*(?:censusEntry)?\{"[A-Za-z0-9_./-]+\.go", "[^"\n]+", "[a-z-]+", "(?:key|sel):[A-Za-z]+(?:,(?:key|sel):[A-Za-z]+)*", "[0-9a-f]{10,63}$''',
]
-regexes = ['''^[0-9a-f]{10,64}$''']
+
+# The same digests in a design checklist's source_hashes: a Go file's path,
+# then the sha256 of that file. Whole line again, for the same reason.
+[[allowlists]]
+description = "design checklist's source digests"
+targetRules = ["generic-api-key"]
+condition = "AND"
+regexTarget = "line"
+paths = ['''^implementation/always-awake-consumers\.json$''']
+regexes = ['''^\s*"[A-Za-z0-9_./-]+\.go": "[0-9a-f]{64}",?\s*$''']
# Fake credentials typed into tests, each recognisable as one: a counting
# run (0123456789abcdef), a word (SecretValue, SENTINEL, nope), a test's