-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Update nancy parser.py #12859
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
base: master
Are you sure you want to change the base?
Update nancy parser.py #12859
Conversation
Nancy latest versions works with CVSS4.0 and "ID" instead of "Id",among others.
This pull request contains a potential information disclosure vulnerability in the
Information Disclosure in Error Message in
|
Vulnerability | Information Disclosure in Error Message |
---|---|
Description | The get_findings method constructs an error message for json.JSONDecodeError by directly embedding the string representation of the exception object. This can lead to information disclosure because json.JSONDecodeError messages often include details about the malformed JSON input, such as the problematic snippet and its location (line/column). If the input JSON contains sensitive data or reveals internal application structure, this information could be exposed to an attacker. |
django-DefectDojo/dojo/tools/nancy/parser.py
Lines 1 to 107 in 57535c9
import json | |
import re | |
from cvss.cvss4 import CVSS4 # Changed from cvss3 to cvss4 | |
from dojo.models import Finding | |
class NancyParser: | |
def get_scan_types(self): | |
return ["Nancy Scan"] | |
def get_label_for_scan_types(self, scan_type): | |
return scan_type # no custom label for now | |
def get_description_for_scan_types(self, scan_type): | |
return ("Nancy output file (go list -json -deps ./... | nancy sleuth > " | |
" nancy.json) can be imported in JSON format.") | |
def requires_file(self, scan_type): | |
return True | |
def get_findings(self, scan_file, test): | |
try: | |
data = json.load(scan_file) | |
except json.JSONDecodeError as e: | |
msg = f"Invalid JSON format: {e}" | |
raise ValueError(msg) | |
if "vulnerable" in data and data["vulnerable"] is not None: | |
return self.get_items(data["vulnerable"], test) | |
else: | |
# If 'vulnerable' is not present or is null, return empty list | |
return [] | |
def get_items(self, vulnerable_list, test): | |
findings = [] | |
for vuln in vulnerable_list: | |
if not vuln.get("Vulnerabilities"): | |
continue | |
try: | |
coordinates = vuln["Coordinates"].split(":") | |
comp_info = coordinates[1].split("@") | |
comp_name = comp_info[0] | |
comp_version = comp_info[1] | |
except (IndexError, KeyError): | |
# Handle cases where coordinate parsing might fail | |
continue | |
for associated_vuln in vuln["Vulnerabilities"]: | |
# The tool does not define severity, but it provides a CVSS vector, | |
# which DefectDojo uses to calculate severity dynamically on save. | |
severity = "Info" | |
# Aggregate references | |
references = [vuln.get("Reference"), associated_vuln.get("Reference")] | |
references = "\n".join(filter(None, references)) | |
finding = Finding( | |
title=associated_vuln.get("Title", "N/A"), | |
description=associated_vuln.get("Description", "No description provided."), | |
test=test, | |
severity=severity, | |
component_name=comp_name, | |
component_version=comp_version, | |
false_p=False, | |
duplicate=False, | |
out_of_scope=False, | |
static_finding=True, | |
dynamic_finding=False, | |
vuln_id_from_tool=associated_vuln.get("ID"), # Changed from "Id" to "ID" | |
references=references, | |
) | |
# Set vulnerability IDs (e.g., CVEs) | |
if cve := associated_vuln.get("Cve"): | |
finding.unsaved_vulnerability_ids = [cve] | |
# Process CVSSv4 vector if available | |
if cvss_vector := associated_vuln.get("CvssVector"): | |
try: | |
# Store the cleaned CVSSv4 vector. DefectDojo will process it. | |
finding.cvssv3 = CVSS4(cvss_vector).clean_vector() | |
except Exception: | |
# Fallback or log error if vector is not valid CVSSv4 | |
pass # Or log a warning | |
# Extract CWE if present in the title using regex for robustness | |
if title := associated_vuln.get("Title", ""): | |
cwe_match = re.search(r"CWE-(\d+)", title, re.IGNORECASE) | |
if cwe_match: | |
try: | |
finding.cwe = int(cwe_match.group(1)) | |
except (ValueError, IndexError): | |
pass # Or log a warning | |
findings.append(finding) | |
return findings |
All finding details can be found in the DryRun Security Dashboard.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please always point the PR against bugfix or dev.
Also, please make the parser backwards compatible. I assume that earlier versions of nancy use CVSS v3?
Defect Dojo 2.49.0 will have a CVSS4 field. There's also some guidance on how to parse CVSS vectors in parsers: https://github.com/DefectDojo/django-DefectDojo/blob/dev/docs/content/en/open_source/contributing/how-to-write-a-parser.md |
Marking this one as a draft until existing comments are addressed |
Nancy latest versions works with CVSS4.0 and "ID" instead of "Id",among others.
We don't want to waste your time, so if you're unsure whether your hypothetical enhancement meets the criteria for approval, please file an issue to get pre-approval before beginning work on a PR.
Learn more here: https://github.com/DefectDojo/django-DefectDojo/blob/master/readme-docs/CONTRIBUTING.md#submission-pre-approval
Description
Describe the feature / bug fix implemented by this PR.
If this is a new parser, the parser guide may be worth (re)reading.
Test results
Ideally you extend the test suite in
tests/
anddojo/unittests
to cover the changed in this PR.Alternatively, describe what you have and haven't tested.
Documentation
Please update any documentation when needed in the documentation folder)
Checklist
This checklist is for your information.
dev
.dev
.bugfix
branch.Extra information
Please clear everything below when submitting your pull request, it's here purely for your information.
Moderators: Labels currently accepted for PRs:
Contributors: Git Tips
Rebase on dev branch
If the dev branch has changed since you started working on it, please rebase your work after the current dev.
On your working branch
mybranch
:In case of conflict:
When everything's fine on your local branch, force push to your
myOrigin
remote:To cancel everything:
Squashing commits
pick
byfixup
on the commits you want squashed outpick
byreword
on the first commit if you want to change the commit messageForce push to your
myOrigin
remote: