-
Notifications
You must be signed in to change notification settings - Fork 1.8k
GitHub Secrets Detection Report Parser #13286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
valentijnscholten
merged 7 commits into
DefectDojo:bugfix
from
Logicmn:github-secret-detection-report-parser
Oct 2, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1fb94a6
Add GitHub secrets detection parser and tests
Logicmn 549c09f
Ruff fixes
Logicmn 5f7a7f1
Add docs and dedupe algo
Logicmn 824ca50
Merge branch 'bugfix' into github-secret-detection-report-parser
valentijnscholten c2e1408
Rm severity from hash_code
Logicmn 9639cbf
Merge branch 'bugfix' into github-secret-detection-report-parser
Logicmn 8d45cad
Merge branch 'bugfix' into github-secret-detection-report-parser
valentijnscholten File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
...ontent/en/connecting_your_tools/parsers/file/github_secrets_detection_report.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
title: "Github Secrets Detection Report" | ||
toc_hide: true | ||
--- | ||
Import findings in JSON format from Github Secret Scanning REST API: | ||
<https://docs.github.com/en/rest/secret-scanning/secret-scanning> | ||
|
||
### Sample Scan Data | ||
Sample Github SAST scans can be found [here](https://github.com/DefectDojo/django-DefectDojo/tree/master/unittests/scans/github_secrets_detection_report_many_vul.json). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
import json | ||
|
||
from dojo.models import Finding | ||
|
||
|
||
class GithubSecretsDetectionReportParser: | ||
def get_scan_types(self): | ||
return ["Github Secrets Detection Report Scan"] | ||
|
||
def get_label_for_scan_types(self, scan_type): | ||
return "Github Secrets Detection Report Scan" | ||
|
||
def get_description_for_scan_types(self, scan_type): | ||
return "Github Secrets Detection Report report file can be imported in JSON format (option --json)." | ||
|
||
def get_findings(self, file, test): | ||
data = json.load(file) | ||
|
||
if not isinstance(data, list): | ||
error_msg = "Invalid GitHub secrets detection report format, expected a JSON list of alerts." | ||
raise TypeError(error_msg) | ||
|
||
findings = [] | ||
for alert in data: | ||
# Extract basic alert information | ||
alert_number = alert.get("number") | ||
state = alert.get("state", "open") | ||
secret_type = alert.get("secret_type", "Unknown") | ||
secret_type_display_name = alert.get("secret_type_display_name", secret_type) | ||
html_url = alert.get("html_url", "") | ||
|
||
# Create title | ||
title = f"Exposed Secret Detected: {secret_type_display_name}" | ||
|
||
# Build description | ||
desc_lines = [] | ||
if html_url: | ||
desc_lines.append(f"**GitHub Alert**: [{html_url}]({html_url})") | ||
|
||
desc_lines.extend([f"**Secret Type**: {secret_type_display_name}", f"**Alert State**: {state}"]) | ||
|
||
# Add repository information | ||
repository = alert.get("repository", {}) | ||
if repository: | ||
repo_full_name = repository.get("full_name") | ||
if repo_full_name: | ||
desc_lines.append(f"**Repository**: {repo_full_name}") | ||
|
||
# Add location information | ||
first_location = alert.get("first_location_detected", {}) | ||
if first_location: | ||
file_path = first_location.get("path") | ||
start_line = first_location.get("start_line") | ||
end_line = first_location.get("end_line") | ||
|
||
if file_path: | ||
desc_lines.append(f"**File Path**: {file_path}") | ||
if start_line: | ||
if end_line and end_line != start_line: | ||
desc_lines.append(f"**Lines**: {start_line}-{end_line}") | ||
else: | ||
desc_lines.append(f"**Line**: {start_line}") | ||
|
||
# Add resolution information | ||
resolution = alert.get("resolution") | ||
if resolution: | ||
desc_lines.append(f"**Resolution**: {resolution}") | ||
|
||
resolved_by = alert.get("resolved_by") | ||
if resolved_by: | ||
resolved_by_login = resolved_by.get("login", "Unknown") | ||
desc_lines.append(f"**Resolved By**: {resolved_by_login}") | ||
|
||
resolved_at = alert.get("resolved_at") | ||
if resolved_at: | ||
desc_lines.append(f"**Resolved At**: {resolved_at}") | ||
|
||
resolution_comment = alert.get("resolution_comment") | ||
if resolution_comment: | ||
desc_lines.append(f"**Resolution Comment**: {resolution_comment}") | ||
|
||
# Add push protection information | ||
push_protection_bypassed = alert.get("push_protection_bypassed", False) | ||
if push_protection_bypassed: | ||
desc_lines.append("**Push Protection Bypassed**: True") | ||
|
||
bypassed_by = alert.get("push_protection_bypassed_by") | ||
if bypassed_by: | ||
bypassed_by_login = bypassed_by.get("login", "Unknown") | ||
desc_lines.append(f"**Bypassed By**: {bypassed_by_login}") | ||
|
||
bypassed_at = alert.get("push_protection_bypassed_at") | ||
if bypassed_at: | ||
desc_lines.append(f"**Bypassed At**: {bypassed_at}") | ||
else: | ||
desc_lines.append("**Push Protection Bypassed**: False") | ||
|
||
# Add additional metadata | ||
validity = alert.get("validity", "unknown") | ||
desc_lines.append(f"**Validity**: {validity}") | ||
|
||
publicly_leaked = alert.get("publicly_leaked", False) | ||
desc_lines.append(f"**Publicly Leaked**: {'Yes' if publicly_leaked else 'No'}") | ||
|
||
multi_repo = alert.get("multi_repo", False) | ||
desc_lines.append(f"**Multi-Repository**: {'Yes' if multi_repo else 'No'}") | ||
|
||
has_more_locations = alert.get("has_more_locations", False) | ||
if has_more_locations: | ||
desc_lines.append("**Note**: This secret has been detected in multiple locations") | ||
|
||
description = "\n\n".join(desc_lines) | ||
|
||
# Determine severity based on state and other factors | ||
if state == "resolved": | ||
severity = "Info" | ||
elif validity == "active" and publicly_leaked: | ||
severity = "Critical" | ||
elif validity == "active": | ||
severity = "High" | ||
else: | ||
severity = "Medium" | ||
|
||
# Create finding | ||
finding = Finding( | ||
title=title, | ||
test=test, | ||
description=description, | ||
severity=severity, | ||
static_finding=True, | ||
dynamic_finding=False, | ||
vuln_id_from_tool=str(alert_number) if alert_number else None, | ||
) | ||
|
||
# Set file path and line information | ||
if first_location: | ||
finding.file_path = first_location.get("path") | ||
finding.line = first_location.get("start_line") | ||
|
||
# Set external URL | ||
if html_url: | ||
finding.url = html_url | ||
|
||
findings.append(finding) | ||
|
||
return findings |
1 change: 1 addition & 0 deletions
1
unittests/scans/github_secrets_detection_report/github_secrets_detection_report_invalid.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.