Skip to content

Commit 174b7d0

Browse files
committed
Update TruffleHog workflow to handle resolved secrets
Adds a workflow step to update the PR comment when previously detected secrets are resolved, marking the PR as clear. Updates documentation to clarify that exclusion patterns are additive, describes the new comment update behavior, and improves the remediation and PR comment sections for clarity.
1 parent c120b09 commit 174b7d0

File tree

2 files changed

+88
-14
lines changed

2 files changed

+88
-14
lines changed

.github/workflows/trufflehog-scan.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,57 @@ Check the [workflow run logs](${{ github.server_url }}/${{ github.repository }}/
164164
});
165165
}
166166
167+
- name: Update PR comment when secrets resolved
168+
if: steps.process.outputs.has_secrets == 'false' && github.event_name != 'workflow_dispatch'
169+
uses: actions/github-script@v7
170+
with:
171+
script: |
172+
const commentMarker = '<!-- TRUFFLEHOG-SCAN-COMMENT -->';
173+
const commitSha = '${{ github.event.pull_request.head.sha }}';
174+
const shortSha = commitSha.substring(0, 7);
175+
const scanTime = new Date().toISOString().replace('T', ' ').substring(0, 19) + ' UTC';
176+
177+
// Check if there's an existing alert comment from a previous failed scan
178+
const { data: comments } = await github.rest.issues.listComments({
179+
owner: context.repo.owner,
180+
repo: context.repo.repo,
181+
issue_number: context.payload.pull_request.number,
182+
per_page: 100
183+
});
184+
185+
const existing = comments.find(c => c.body && c.body.includes(commentMarker));
186+
187+
// Only update if there was a previous alert - don't create new comments for clean scans
188+
if (existing) {
189+
const resolvedBody = `${commentMarker}
190+
## :white_check_mark: Secret Scanning Passed
191+
192+
**Previously detected secrets have been resolved.**
193+
194+
| Scan Details | |
195+
|--------------|---|
196+
| **Commit** | [\`${shortSha}\`](${{ github.server_url }}/${{ github.repository }}/commit/${commitSha}) |
197+
| **Scanned At** | ${scanTime} |
198+
| **Workflow Run** | [View Logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) |
199+
200+
The secrets flagged in previous scans are no longer detected in the modified files.
201+
202+
---
203+
*This PR is now clear of detected secrets. Remember to rotate any credentials that were previously exposed.*
204+
`;
205+
206+
await github.rest.issues.updateComment({
207+
owner: context.repo.owner,
208+
repo: context.repo.repo,
209+
comment_id: existing.id,
210+
body: resolvedBody
211+
});
212+
213+
console.log('Updated existing alert comment to show resolved status');
214+
} else {
215+
console.log('No previous alert comment found - scan passed cleanly');
216+
}
217+
167218
- name: Set commit status
168219
if: github.event_name != 'workflow_dispatch'
169220
uses: actions/github-script@v7

trufflehog_readme.md

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,14 @@ Exclusions are configured via the `TRUFFLEHOG_EXCLUDES` variable using regex pat
8888

8989
## Override at Repository Level
9090

91-
Individual repos can override org defaults:
91+
Individual repos can add additional exclusions on top of the defaults:
9292

9393
1. Go to **Repository** > **Settings** > **Secrets and variables** > **Actions**
9494
2. Click **Variables** tab > **New repository variable**
9595
3. Name: `TRUFFLEHOG_EXCLUDES`
9696
4. Value: Your comma-separated regex patterns
9797

98-
This completely replaces org-level patterns for that repository.
98+
**Exclusions are additive:** Your patterns are combined with the default exclusions. You don't need to repeat common patterns like `node_modules/` or `.lock` files.
9999

100100
## Default Exclusions
101101

@@ -166,15 +166,22 @@ Determine PR Type
166166
Secrets found No secrets found
167167
| |
168168
v v
169-
Post PR comment Set commit status
170-
with findings to success
171-
| |
172-
v v
173-
Set commit status PASS - PR allowed
174-
to failure
175-
|
176-
v
177-
FAIL - PR blocked
169+
Post/Update PR Check for previous
170+
comment with alert comment
171+
findings |
172+
| +--------+--------+
173+
| | |
174+
v v v
175+
Set commit status Exists? No comment
176+
to failure | (clean PR)
177+
| v |
178+
v Update to v
179+
FAIL - PR "Resolved" Set commit status
180+
blocked status to success
181+
| |
182+
v v
183+
Set commit PASS - PR allowed
184+
to success
178185
```
179186

180187
**Scan scope:** Only files modified in the PR are scanned, not the entire repository.
@@ -190,12 +197,27 @@ TruffleHog classifies detected secrets into two categories:
190197

191198
## PR Comments
192199

193-
When secrets are detected, the workflow automatically posts a comment on the PR with:
200+
The workflow manages PR comments to provide clear feedback throughout the remediation process:
201+
202+
### When Secrets Are Detected
203+
204+
A comment is posted with:
205+
- Commit SHA that was scanned
206+
- Timestamp of the scan
194207
- Link to workflow logs for detailed findings
195208
- Instructions for removing and rotating secrets
196209
- Information about file paths, line numbers, and secret types
197210

198-
When no secrets are found, no comment is posted to keep the PR clean.
211+
### When Secrets Are Resolved
212+
213+
If you fix the secrets and push again:
214+
- The **same comment is updated** to show a "Passed" status
215+
- Shows the new commit SHA that resolved the issue
216+
- Includes a reminder to rotate any previously exposed credentials
217+
218+
### Clean PRs
219+
220+
If a PR never had secrets detected, no comment is posted to keep the PR clean.
199221

200222
## Workflow Triggers
201223

@@ -240,8 +262,9 @@ If the scan fails:
240262
2. **Rotate the secret** immediately (assume it's compromised)
241263
3. **Push the fix** to your PR branch
242264
4. Scan re-runs automatically
265+
5. PR comment updates to show "Resolved" status when fixed
243266

244-
**For false positives:** Add the file/pattern to repo-level `TRUFFLEHOG_EXCLUDES` or request an update to org-level patterns.
267+
**For false positives:** Add the file/pattern to repo-level `TRUFFLEHOG_EXCLUDES` (patterns are additive to defaults).
245268

246269
## Manual Scan
247270

0 commit comments

Comments
 (0)