Skip to content

Conversation

@mfyll
Copy link

@mfyll mfyll commented Oct 29, 2025

Add OpenReports JSON Import Parser

Description

Adds support for importing scans in OpenReports.io format. Currently only statnett operator outputs trivy scans in this format, but being an open standard backed by e.g kyverno, more tools could adopt it.

More information can be found here: OpenReports.io

Steps to get the relevant file:

kubectl get reports -ojson -A > reports.json

Features:

  • Parses single reports and Kubernetes List objects
  • Extracts CVE IDs, component versions, and fix availability
  • Maps severity levels and creates proper service identifiers
  • Handles vulnerability metadata and tagging

Test results

Added unit tests covering empty results, single reports, list format, and parser metadata. All tests pass with sample JSON files included.

I have also tested this by importing the resulting JSON file in the DefectDojo GUI and this works.

Documentation

Parser follows standard DefectDojo interface with inline documentation and sample files.

Checklist

  • Rebased against latest dev
  • Submitted against dev branch
  • Flake8 and Python 3.12 compliant
  • Unit tests added

@dryrunsecurity
Copy link

dryrunsecurity bot commented Oct 29, 2025

DryRun Security

This pull request introduces a potential resource exhaustion (Denial of Service) issue: the OpenReports parser reads the entire uploaded JSON report into memory via scan_file.read() and json.loads(), which can consume large amounts of memory for big or malicious files and crash worker processes. Consider streaming or incremental parsing, enforcing strict upload size limits, or validating/sanitizing input before full parsing to mitigate the risk.

Resource Exhaustion (Denial of Service) in dojo/tools/openreports/parser.py
Vulnerability Resource Exhaustion (Denial of Service)
Description The OpenReports parser reads the entire uploaded JSON report file into memory using scan_file.read() and then json.loads(). This process can lead to significant memory consumption, especially with large or maliciously crafted JSON files, potentially causing a Denial of Service (DoS) by exhausting the application's memory resources and crashing the worker process. Even if there are file upload size limits, the memory amplification during JSON parsing can still be substantial.

data = json.loads(str(scan_data, "utf-8"))
except Exception:
data = json.loads(scan_data)


All finding details can be found in the DryRun Security Dashboard.

Copy link
Member

@valentijnscholten valentijnscholten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! It looks quite good already. Some questions:

  • Can you add at least one vulnerability for which the policy field is not a CVE?
  • Could you look at the hash_code configuration for deduplication? It might be good to check wha the best fit ir or if there's a field that we can use as a value for unique_id_from_tool.

Copy link
Contributor

@manuel-sommer manuel-sommer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add a documentation file for the parser.

@github-actions github-actions bot added settings_changes Needs changes to settings.py based on changes in settings.dist.py included in this PR docs labels Oct 30, 2025
@mfyll mfyll force-pushed the add-openreports-import branch from 8cbb5ca to 7647272 Compare October 30, 2025 10:15
@valentijnscholten valentijnscholten added this to the 2.52.0 milestone Oct 30, 2025
@valentijnscholten
Copy link
Member

I think also if this is a generic report format similar to SARIF, the openreports parser should do something similar where the actual report type / scanner type ends up in the test name in Defect Dojo.
I believe something happens here:

test = ParserTest(
name=run["tool"]["driver"]["name"],
parser_type=run["tool"]["driver"]["name"],
version=run["tool"]["driver"].get("version"),
)

@mfyll mfyll force-pushed the add-openreports-import branch from 01dc290 to 53ef8bb Compare October 31, 2025 07:48
Copy link
Member

@valentijnscholten valentijnscholten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for extending the PR. The values for the scanner names seem a bit generic and may change in the future if more operators/scanners will use this output format, but that's outside our control.

Copy link
Member

@valentijnscholten valentijnscholten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, forgot that there were some small issues to address.


# Set vuln_id_from_tool to the policy field for deduplication
# This allows using DEDUPE_ALGO_UNIQUE_ID_FROM_TOOL_OR_HASH_CODE
finding.vuln_id_from_tool = policy
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@valentijnscholten Will this work?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the field is unique_id_from_tool. But it must be unique per finding and across multiple scans/import.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I am blind. Then the correct way would be hashing, like you previously mentioned.

@valentijnscholten valentijnscholten removed this from the 2.52.0 milestone Nov 3, 2025
@valentijnscholten valentijnscholten added this to the 2.53.0 milestone Nov 3, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 4, 2025

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 5, 2025

Conflicts have been resolved. A maintainer will review the pull request shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs parser settings_changes Needs changes to settings.py based on changes in settings.dist.py included in this PR unittests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants