Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
720b203
add detector corpora test workflow and script
mustansir14 Apr 29, 2026
942b25f
only run once per PR, make comment descriptive, add handling for manu…
mustansir14 Apr 29, 2026
27b8867
comment out types to see result on all commits
mustansir14 Apr 29, 2026
e360e6d
uncomment types
mustansir14 Apr 29, 2026
1aae080
remove table from comment
mustansir14 Apr 29, 2026
0a78ecc
comment out types
mustansir14 Apr 29, 2026
b9d8506
Phase 0: add explicit pipefail and capture trufflehog stderr
shahzadhaider1 Apr 29, 2026
26c1c03
Phase 1: differential diffing PR vs main
shahzadhaider1 Apr 29, 2026
f46e86c
DEMO: loosen Stripe regex (will revert)
shahzadhaider1 Apr 29, 2026
021e8c3
DEMO: loosen JDBC regex (will revert)
shahzadhaider1 Apr 29, 2026
420ec56
Phase 1 fix: add --allow-verification-overlap, fix no-diff detection
shahzadhaider1 Apr 29, 2026
b0c3d28
revert jdbc detector change
shahzadhaider1 Apr 29, 2026
25f08fc
Phase 2: detector scoping, new-detector handling, blast radius, statu…
shahzadhaider1 Apr 29, 2026
735522b
DEMO: loosen JDBC + add fictional acmevault detector
shahzadhaider1 Apr 29, 2026
7b44c92
Phase 2 fix: harden corpus byte counting against early trufflehog exit
shahzadhaider1 May 1, 2026
e0e33bc
Phase 3a (1/3): add hack/extract-keywords for detector keyword intros…
shahzadhaider1 May 2, 2026
a93890e
Phase 3a (2/3): add Layer 1 keyword corpus builder + workflow integra…
shahzadhaider1 May 2, 2026
24fdf36
Phase 4 complete - Heatmap visualization
shahzadhaider1 May 2, 2026
c20a5dd
Phase 4 rework (1/2): emit heatmap-grid.json sidecar from render_heat…
shahzadhaider1 May 2, 2026
80f6747
Phase 4 rework (2/2): replace data-URL embed with emoji-bucketed Mark…
shahzadhaider1 May 2, 2026
02ae97b
Phase 5 complete - Polish
shahzadhaider1 May 2, 2026
5186d12
cleanup, enable verification
mustansir14 May 4, 2026
bbaa4af
fix bug
mustansir14 May 4, 2026
648ae6a
optimizations
mustansir14 May 4, 2026
b56b46b
cache keywords corpus
mustansir14 May 4, 2026
3284602
rewrite comment message
mustansir14 May 4, 2026
2421212
cache github api corpus per keyword
mustansir14 May 4, 2026
6ba2661
cleanup
mustansir14 May 4, 2026
a00d129
remove github corpus
mustansir14 May 4, 2026
8a20a97
revert changes for testing
mustansir14 May 4, 2026
30c98bb
move Configure AWS credentials step to run only when detector changes…
mustansir14 May 4, 2026
0d852e6
revert unnecessary changes
mustansir14 May 4, 2026
624cfbe
cleanup + bugbot fixes
mustansir14 May 4, 2026
f222e57
run test with bigger (30gb) dataset, loosen jdbc regex
mustansir14 May 4, 2026
d0d94a2
optimizations
mustansir14 May 4, 2026
dacf850
bugbot fixes
mustansir14 May 4, 2026
1cf22a8
revert jdbc changes and bugbot fix
mustansir14 May 4, 2026
5792a09
run only on regex and/or keywords change
mustansir14 May 4, 2026
032b2a8
bugbot fixes
mustansir14 May 4, 2026
c53fbcb
Merge branch 'main' into hackathon/detector-tests-in-ci
mustansir14 May 4, 2026
88c63e6
bugbot fix
mustansir14 May 4, 2026
f7f08e6
Merge branch 'hackathon/detector-tests-in-ci' of mustansir:trufflesec…
mustansir14 May 4, 2026
5a6e1a2
incorporate brad's comments, loosen jdbc regex to run a test to ensur…
mustansir14 May 5, 2026
5b722a2
revert test changes
mustansir14 May 5, 2026
6c3bbae
fix misleading bench skipped message
mustansir14 May 5, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions .github/workflows/detector-corpora-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: Corpora Test

on:
workflow_dispatch:
pull_request:
# types: [opened, reopened] TODO: Decide if we should run this on every push
paths:
- 'pkg/detectors/**'
- '.github/workflows/detector-corpora-test.yml'
- 'scripts/detector_corpora_test.sh'

env:
DATASETS: |
s3://trufflehog-corpora-datasets/contents.2025-11-04.jsonl.zstd

jobs:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, some of the actions used here are old versions. Also, you might consider pinning the action versions used here to reduce risk of possible supply-chain attacks.

zizmor is helpful: https://docs.zizmor.sh/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. Really helpful! I'll do the needful

corpora-test:
if: ${{ github.repository == 'trufflesecurity/trufflehog' && !github.event.pull_request.head.repo.fork }}
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v5
with:
go-version: "1.25"

- name: Install dependencies
run: sudo apt-get install -y zstd jq

- name: Install DuckDB
run: |
wget -q https://github.com/duckdb/duckdb/releases/latest/download/duckdb_cli-linux-amd64.zip
unzip duckdb_cli-linux-amd64.zip
sudo mv duckdb /usr/local/bin/

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: Run corpora test
run: |
files=()
while IFS= read -r dataset; do
[[ -z "$dataset" ]] && continue
files+=("$dataset")
done <<< "$DATASETS"
./scripts/detector_corpora_test.sh "${files[@]}" | tee /tmp/corpora-results.txt
Comment thread
cursor[bot] marked this conversation as resolved.
Outdated

- name: Post results to PR
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const results = fs.readFileSync('/tmp/corpora-results.txt', 'utf8');
const body = [
`## Corpora Test Results`,
``,
`This test scans a real-world dataset of public content to measure how often this detector fires. A high number of unverified or unknown results may indicate the detector is too noisy and could impact signal quality in production.`,
``,
`\`\`\``,
results,
`\`\`\``,
].join('\n');
let issue_number;
if (context.eventName === 'workflow_dispatch') {
const pulls = await github.rest.pulls.list({
owner: context.repo.owner,
repo: context.repo.repo,
head: `${context.repo.owner}:${context.ref.replace('refs/heads/', '')}`,
state: 'open',
});
if (pulls.data.length === 0) {
core.setFailed(`No open PR found for branch ${context.ref}`);
return;
}
issue_number = pulls.data[0].number;
} else {
issue_number = context.issue.number;
}
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number,
body,
});
Comment thread
cursor[bot] marked this conversation as resolved.
Outdated
52 changes: 52 additions & 0 deletions scripts/detector_corpora_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash
set -euo pipefail

if [[ $# -lt 1 ]]; then
echo "Usage: $0 <corpora_file.jsonl.zstd> [<corpora_file2.jsonl.zstd> ...]"
exit 1
fi

OUTPUT_JSONL="/tmp/corpora_results.jsonl"
> "$OUTPUT_JSONL"

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(dirname "$SCRIPT_DIR")"
TRUFFLEHOG_BIN="${REPO_ROOT}/trufflehog"

CGO_ENABLED=0 go build -o "$TRUFFLEHOG_BIN" "$REPO_ROOT"

scan() {
local input="$1"
set +e
unzstd -c "$input" | jq -r .content | "$TRUFFLEHOG_BIN" \
--no-update \
--log-level=3 \
--concurrency=6 \
--json \
--print-avg-detector-time \
stdin >> "$OUTPUT_JSONL" 2>/dev/null
set -e
}

for CORPORA_FILE in "$@"; do
if [[ "$CORPORA_FILE" == s3://* ]]; then
aws s3 cp "$CORPORA_FILE" - | scan /dev/stdin
else
scan "$CORPORA_FILE"
fi
done

duckdb -c "
CREATE TABLE t AS FROM read_json_auto('$OUTPUT_JSONL', ignore_errors=true);

SELECT
t.DetectorName detector,
COUNT(*) total,
SUM(CASE WHEN Verified AND VerificationError IS NULL THEN 1 ELSE 0 END) verified,
SUM(CASE WHEN NOT Verified AND VerificationError IS NULL THEN 1 ELSE 0 END) unverified,
SUM(CASE WHEN VerificationError IS NOT NULL THEN 1 ELSE 0 END) \"unknown\"
FROM t
GROUP BY all
ORDER BY total DESC, detector
LIMIT 50;
"
Loading