Skip to content
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

Enhance OSV Parser to Include Mitigation Information with Fixed Package Versions #11681

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from

Conversation

4b75726169736859
Copy link

⚠️ Note on feature completeness ⚠️

This pull request aligns with the current contribution guidelines by enhancing the OSV parser. The changes introduce mitigation details for vulnerabilities.


Description

This pull request enhances the OSC Scan parser by adding support for mitigation information, specifically the fixed versions of affected packages.

Key Changes:

  1. Extraction of Fixed Versions:

    • Added logic to parse the ranges field within the affected section of each vulnerability.
    • Extracted the fixed version from the events list when available and formatted it as:
      Upgrade to version: <fixed_version>.
  2. Integration of Mitigation:

    • Introduced a new mitigation field in findings to provide actionable guidance for resolving vulnerabilities.
  3. Enhanced Usability:

    • Improved the output of the parser to make it more informative and aligned with best practices in vulnerability management.
  4. Testing Support:

    • Standalone Python script to test the parser. The script reads a sample JSON file, executes the parser, and outputs the findings, including the mitigation details, for validation.

Test Results

Testing was conducted using the provided sample JSON file (test.json). The parser correctly identifies findings and includes mitigation details in its output.

Example Output:

  • Title: CVE-2024-50252_linux
  • Severity: Medium
  • Mitigation: Upgrade to version: 6.1.119-1
  • Description: Detailed vulnerability information.
  • References: Links to relevant advisories and fixes.

Additionally, I verified that:

  • Findings without a fixed version omit the mitigation field.
  • The parser handles malformed JSON gracefully by returning an empty findings list.

Although unit tests are planned to extend dojo/unittests, I was unable to complete them as I did not fully understand their functionality. However, I took screenshots of the final output to validate the results.

Capture d’écran du 2025-01-15 15-42-10
Capture d’écran du 2025-01-15 15-42-22


Documentation

The documentation has been updated to reflect this new feature:

  • Added a note about the mitigation field in the parser's description.
  • Clarified that mitigation information will appear when available in the input JSON.

Checklist

  • Changes submitted against the dev branch.
  • PR named meaningfully for release notes.
  • Code is flake8 and Python 3.11 compliant.
  • Tests added to validate the parser's new functionality.
  • Proper label applied: Import Scans.

Labels

Import Scans, enhancement


Extra Information

This pull request enhances the usability of the OSV parser, making it more actionable by including mitigation details. It also aligns with existing parsers, such as WPScan, which already support fixed versions, ensuring consistency across DefectDojo.


If you need further clarifications or adjustments, feel free to let me know!

Copy link

dryrunsecurity bot commented Jan 28, 2025

DryRun Security Summary

The code changes enhance the OSV scanner parser in DefectDojo by improving vulnerability data extraction (including mitigation, CWE details, and references) and adding comprehensive unit tests to ensure reliable processing of security findings.

Expand for full summary

Summary:

The provided code changes focus on enhancing the functionality of the OSV (Open-Source Vulnerabilities) scanner parser in the DefectDojo application security tool. The key improvements include the ability to extract mitigation information, CWE (Common Weakness Enumeration) details, and comprehensive references for the identified vulnerabilities. These changes help provide more detailed and actionable information to the DefectDojo users, which is an important aspect of effective application security.

Additionally, the code changes include a comprehensive set of unit tests for the OSVScannerParser class, covering various scenarios such as no findings, some findings, and many findings. The test cases validate the correct extraction and storage of critical vulnerability information, including vulnerability references, mitigation details, static findings, and severity levels. This thorough testing approach helps ensure the reliability and accuracy of the vulnerability data processed by the application.

Files Changed:

  1. dojo/tools/osv_scanner/parser.py:

    • Added the ability to extract the "fixed" version information from the vulnerability data and store it in the mitigation field of the Finding object.
    • Correctly extracts the CWE (Common Weakness Enumeration) identifier from the vulnerability data and associates it with the Finding object.
    • Ensures that all references associated with a vulnerability are properly captured and included in the Finding object.
    • Handles the case where the references field in the vulnerability data is empty, preventing potential errors or missing information.
  2. unittests/tools/test_osv_scanner_parser.py:

    • Covers various test cases, including no findings, some findings, and many findings.
    • Verifies the correct extraction and storage of vulnerability references, mitigation information, static findings, and severity levels.
    • Ensures the parser handles different types of vulnerability identifiers, such as CVEs and GHSA (GitHub Security Advisory) IDs.

Code Analysis

We ran 9 analyzers against 2 files and 0 analyzers had findings. 9 analyzers had no findings.

View PR in the DryRun Dashboard.

@4b75726169736859
Copy link
Author

@4b75726169736859
Copy link
Author

Sorry, here is the unittest test.
inittest_osv_scanner_new_pr.log

4b75726169736859

This comment was marked as resolved.

@manuel-sommer
Copy link
Contributor

Could you also fix the ruff linter @4b75726169736859 ?

@4b75726169736859
Copy link
Author

Could you also fix the ruff linter @4b75726169736859 ?

yes just after my work day

Copy link
Author

@4b75726169736859 4b75726169736859 left a comment

Choose a reason for hiding this comment

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

Adding empty line

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

Successfully merging this pull request may close these issues.

2 participants