Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
85 changes: 51 additions & 34 deletions dojo/fixtures/dojo_testdata.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
[
{
"pk": 1,
"model": "dojo.sla_configuration",
"fields": {
"name": "Default SLA Configuration",
"description": "Default SLA configuration for testing",
"critical": 7,
"enforce_critical": true,
"high": 30,
"enforce_high": true,
"medium": 90,
"enforce_medium": true,
"low": 120,
"enforce_low": false,
"restart_sla_on_reactivation": false
}
},
{
"pk": 1,
"model": "auth.user",
Expand Down Expand Up @@ -184,40 +201,40 @@
"remote_addr": null,
"timestamp": "2021-10-22T01:24:54.921Z",
"additional_data": null
}
},
{
"model": "auditlog.logentry",
"pk": 804,
"fields": {
"content_type": 28,
"object_pk": "2",
"object_id": 2,
"object_repr": "Internal CRM App",
"action": 0,
"changes": "{\"product\": [\"None\", \"dojo.Cred_Mapping.None\"], \"product_meta\": [\"None\", \"dojo.DojoMeta.None\"], \"name\": [\"None\", \"Internal CRM App\"], \"description\": [\"None\", \"* New product in development that attempts to follow all best practices\"], \"product_manager\": [\"None\", \"(product_manager)\"], \"technical_contact\": [\"None\", \"(product_manager)\"], \"team_manager\": [\"None\", \"(user2)\"], \"prod_type\": [\"None\", \"Commerce\"], \"id\": [\"None\", \"2\"], \"tid\": [\"None\", \"0\"], \"business_criticality\": [\"None\", \"medium\"], \"platform\": [\"None\", \"web\"], \"lifecycle\": [\"None\", \"construction\"], \"origin\": [\"None\", \"internal\"], \"external_audience\": [\"None\", \"False\"], \"internet_accessible\": [\"None\", \"False\"], \"enable_simple_risk_acceptance\": [\"None\", \"False\"], \"enable_full_risk_acceptance\": [\"None\", \"True\"]}",
"actor": null,
"remote_addr": null,
"timestamp": "2021-10-22T01:24:55.044Z",
"additional_data": null
}
},
{
"model": "auditlog.logentry",
"pk": 805,
"fields": {
"content_type": 28,
"object_pk": "3",
"object_id": 3,
"object_repr": "Apple Accounting Software",
"action": 0,
"changes": "{\"product\": [\"None\", \"dojo.Cred_Mapping.None\"], \"product_meta\": [\"None\", \"dojo.DojoMeta.None\"], \"name\": [\"None\", \"Apple Accounting Software\"], \"description\": [\"None\", \"Accounting software is typically composed of various modules, different sections dealing with particular areas of accounting. Among the most common are:\\r\\n\\r\\n**Core modules**\\r\\n\\r\\n* Accounts receivable\\u2014where the company enters money received\\r\\n* Accounts payable\\u2014where the company enters its bills and pays money it owes\\r\\n* General ledger\\u2014the company's \\\"books\\\"\\r\\n* Billing\\u2014where the company produces invoices to clients/customers\"], \"product_manager\": [\"None\", \"(admin)\"], \"technical_contact\": [\"None\", \"(user2)\"], \"team_manager\": [\"None\", \"(user2)\"], \"prod_type\": [\"None\", \"Billing\"], \"id\": [\"None\", \"3\"], \"tid\": [\"None\", \"0\"], \"business_criticality\": [\"None\", \"high\"], \"platform\": [\"None\", \"web\"], \"lifecycle\": [\"None\", \"production\"], \"origin\": [\"None\", \"purchased\"], \"user_records\": [\"None\", \"5000\"], \"external_audience\": [\"None\", \"True\"], \"internet_accessible\": [\"None\", \"False\"], \"enable_simple_risk_acceptance\": [\"None\", \"False\"], \"enable_full_risk_acceptance\": [\"None\", \"True\"]}",
"actor": null,
"remote_addr": null,
"timestamp": "2021-10-22T01:24:55.071Z",
"additional_data": null
}
},
}
},
{
"model": "auditlog.logentry",
"pk": 804,
"fields": {
"content_type": 28,
"object_pk": "2",
"object_id": 2,
"object_repr": "Internal CRM App",
"action": 0,
"changes": "{\"product\": [\"None\", \"dojo.Cred_Mapping.None\"], \"product_meta\": [\"None\", \"dojo.DojoMeta.None\"], \"name\": [\"None\", \"Internal CRM App\"], \"description\": [\"None\", \"* New product in development that attempts to follow all best practices\"], \"product_manager\": [\"None\", \"(product_manager)\"], \"technical_contact\": [\"None\", \"(product_manager)\"], \"team_manager\": [\"None\", \"(user2)\"], \"prod_type\": [\"None\", \"Commerce\"], \"id\": [\"None\", \"2\"], \"tid\": [\"None\", \"0\"], \"business_criticality\": [\"None\", \"medium\"], \"platform\": [\"None\", \"web\"], \"lifecycle\": [\"None\", \"construction\"], \"origin\": [\"None\", \"internal\"], \"external_audience\": [\"None\", \"False\"], \"internet_accessible\": [\"None\", \"False\"], \"enable_simple_risk_acceptance\": [\"None\", \"False\"], \"enable_full_risk_acceptance\": [\"None\", \"True\"]}",
"actor": null,
"remote_addr": null,
"timestamp": "2021-10-22T01:24:55.044Z",
"additional_data": null
}
},
{
"model": "auditlog.logentry",
"pk": 805,
"fields": {
"content_type": 28,
"object_pk": "3",
"object_id": 3,
"object_repr": "Apple Accounting Software",
"action": 0,
"changes": "{\"product\": [\"None\", \"dojo.Cred_Mapping.None\"], \"product_meta\": [\"None\", \"dojo.DojoMeta.None\"], \"name\": [\"None\", \"Apple Accounting Software\"], \"description\": [\"None\", \"Accounting software is typically composed of various modules, different sections dealing with particular areas of accounting. Among the most common are:\\r\\n\\r\\n**Core modules**\\r\\n\\r\\n* Accounts receivable\\u2014where the company enters money received\\r\\n* Accounts payable\\u2014where the company enters its bills and pays money it owes\\r\\n* General ledger\\u2014the company's \\\"books\\\"\\r\\n* Billing\\u2014where the company produces invoices to clients/customers\"], \"product_manager\": [\"None\", \"(admin)\"], \"technical_contact\": [\"None\", \"(user2)\"], \"team_manager\": [\"None\", \"(user2)\"], \"prod_type\": [\"None\", \"Billing\"], \"id\": [\"None\", \"3\"], \"tid\": [\"None\", \"0\"], \"business_criticality\": [\"None\", \"high\"], \"platform\": [\"None\", \"web\"], \"lifecycle\": [\"None\", \"production\"], \"origin\": [\"None\", \"purchased\"], \"user_records\": [\"None\", \"5000\"], \"external_audience\": [\"None\", \"True\"], \"internet_accessible\": [\"None\", \"False\"], \"enable_simple_risk_acceptance\": [\"None\", \"False\"], \"enable_full_risk_acceptance\": [\"None\", \"True\"]}",
"actor": null,
"remote_addr": null,
"timestamp": "2021-10-22T01:24:55.071Z",
"additional_data": null
}
},
{
"pk": 1,
"model": "dojo.system_settings",
Expand Down
36 changes: 21 additions & 15 deletions dojo/importers/default_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,12 @@


class DefaultImporter(BaseImporter, DefaultImporterOptions):

"""
The classic importer process used by DefectDojo

This Importer is intended to be used when auditing the history
of findings at a given point in time is required
"""

Check failure on line 48 in dojo/importers/default_importer.py

View workflow job for this annotation

GitHub Actions / ruff-linting

Ruff (D203)

dojo/importers/default_importer.py:43:5: D203 1 blank line required before class docstring

def __init__(self, *args, **kwargs):
super().__init__(
Expand Down Expand Up @@ -89,7 +88,7 @@
scan: TemporaryUploadedFile,
*args: list,
**kwargs: dict,
) -> tuple[Test, int, int, int, int, int, Test_Import]:
) -> tuple[Test, int, int, int, int, int, Test_Import, dict]:
"""
The full step process of taking a scan report, and converting it to
findings in the database. This entails the the following actions:
Expand Down Expand Up @@ -150,7 +149,7 @@
logger.debug("IMPORT_SCAN: Updating Test progress")
self.update_test_progress()
logger.debug("IMPORT_SCAN: Done")
return self.test, 0, len(new_findings), len(closed_findings), 0, 0, test_import_history
return self.test, 0, len(new_findings), len(closed_findings), 0, 0, test_import_history, {}

def process_findings(
self,
Expand Down Expand Up @@ -178,7 +177,12 @@
for raw_finding in parsed_findings or []:
sanitized = self.sanitize_severity(raw_finding)
if Finding.SEVERITIES[sanitized.severity] > Finding.SEVERITIES[self.minimum_severity]:
logger.debug("skipping finding due to minimum severity filter (finding=%s severity=%s min=%s)", sanitized.title, sanitized.severity, self.minimum_severity)
logger.debug(
"skipping finding due to minimum severity filter (finding=%s severity=%s min=%s)",
sanitized.title,
sanitized.severity,
self.minimum_severity,
)
continue
cleaned_findings.append(sanitized)

Expand All @@ -194,7 +198,13 @@
unsaved_finding.reporter = self.user
unsaved_finding.last_reviewed_by = self.user
unsaved_finding.last_reviewed = self.now
logger.debug("process_parsed_finding: unique_id_from_tool: %s, hash_code: %s, active from report: %s, verified from report: %s", unsaved_finding.unique_id_from_tool, unsaved_finding.hash_code, unsaved_finding.active, unsaved_finding.verified)
logger.debug(
"process_parsed_finding: unique_id_from_tool: %s, hash_code: %s, active from report: %s, verified from report: %s",
unsaved_finding.unique_id_from_tool,
unsaved_finding.hash_code,
unsaved_finding.active,
unsaved_finding.verified,
)
# indicates an override. Otherwise, do not change the value of unsaved_finding.active
if self.active is not None:
unsaved_finding.active = self.active
Expand Down Expand Up @@ -260,7 +270,7 @@
# Execute task immediately for synchronous processing
post_processing_task_signature()

for (group_name, findings) in group_names_to_findings_dict.items():
for group_name, findings in group_names_to_findings_dict.items():
finding_helper.add_findings_to_auto_group(
group_name,
findings,
Expand Down Expand Up @@ -332,10 +342,7 @@
if self.deduplication_algorithm == "unique_id_from_tool_or_hash_code":
old_findings = old_findings.exclude(
(Q(hash_code__isnull=False) & Q(hash_code__in=new_hash_codes))
| (
Q(unique_id_from_tool__isnull=False)
& Q(unique_id_from_tool__in=new_unique_ids_from_tool)
),
| (Q(unique_id_from_tool__isnull=False) & Q(unique_id_from_tool__in=new_unique_ids_from_tool)),
)
# Accommodate for product scope or engagement scope
if self.close_old_findings_product_scope:
Expand All @@ -351,16 +358,15 @@
for old_finding in old_findings:
self.mitigate_finding(
old_finding,
(
"This finding has been automatically closed "
"as it is not present anymore in recent scans."
),
("This finding has been automatically closed as it is not present anymore in recent scans."),
finding_groups_enabled=self.findings_groups_enabled,
product_grading_option=False,
)
# push finding groups to jira since we only only want to push whole groups
if self.findings_groups_enabled and self.push_to_jira:
for finding_group in {finding.finding_group for finding in old_findings if finding.finding_group is not None}:
for finding_group in {
finding.finding_group for finding in old_findings if finding.finding_group is not None
}:
jira_helper.push_to_jira(finding_group)

# Calculate grade once after all findings have been closed
Expand Down
Loading
Loading