Skip to content

Commit c6ad7ed

Browse files
authored
Merge pull request #16 from devrev/jro/mask_merge_messages
Mask detections of github token is commit messages.
2 parents 07c79a7 + e0add9b commit c6ad7ed

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

checks/check_trufflehog.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,21 @@ def check_trufflehog(json_path):
6060
if len(line) == 0:
6161
continue
6262
finding = json.loads(line)
63+
detector_name = finding["DetectorName"]
6364
git_info = finding["SourceMetadata"]["Data"]["Git"]
64-
fn = git_info["file"]
65+
fn = git_info.get("file")
6566
line_num = git_info["line"]
67+
68+
# Special handling for github tokens in commit messages:
69+
if detector_name == "Github" and fn is None:
70+
print(f"Skipping {detector_name} finding because detection is in commit message")
71+
continue
6672
if is_overridden(fn, line_num, cred_overrides):
6773
print(f"Skipping {fn}:{line_num} because it is in the creds.yml file")
6874
continue
75+
if fn is None:
76+
# Clarify that the finding is in a commit message.
77+
print(f"<commit message>")
6978
print(f"Found secret in {fn}:{line_num}")
7079
return False
7180
print("No secrets found")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"SourceMetadata":{"Data":{"Git":{"commit":"306419ec2a79f5ddb4117185f104c80004e342b6","email":"Jan Olderdissen \u003c[email protected]\u003e","repository":"[email protected]:devrev/jano-experimental.git","timestamp":"2025-09-25 17:20:44 +0000","line":4,"repository_local_path":"."}}},"SourceID":1,"SourceType":16,"SourceName":"trufflehog - git","DetectorType":8,"DetectorName":"Github","DetectorDescription":"GitHub is a platform for version control and collaboration. Personal access tokens (PATs) can be used to access and modify repositories and other resources.","DecoderName":"PLAIN","Verified":false,"VerificationFromCache":false,"Raw":"ghp_c2cc08e5b98f8995bb8042c5adb024e46f42","RawV2":"","Redacted":"","ExtraData":{"rotation_guide":"https://howtorotate.com/docs/tutorials/github/","version":"2"},"StructuredData":null}

checks/test_checks.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ def test_two_overrides(self):
6363
self.assertTrue(checks.check_trufflehog.check_trufflehog(
6464
"./trufflehog.json"))
6565

66+
def test_merge_message(self):
67+
with change_dir("checks/fixtures/trufflehog/merge_message"):
68+
self.assertTrue(checks.check_trufflehog.check_trufflehog(
69+
"./trufflehog.json"))
70+
6671
class TestCommitEmails(unittest.TestCase):
6772
def test_good(self):
6873
with change_dir("checks/fixtures/emails/good"):

0 commit comments

Comments
 (0)