Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

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
merged 21 commits into from
Apr 30, 2025

Conversation

4b75726169736859
Copy link
Contributor

@4b75726169736859 4b75726169736859 commented Jan 28, 2025

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 patch improves the OSV scanner parser by enhancing vulnerability information extraction, input validation, mitigation details parsing, and adding comprehensive unit testing for security vulnerability tracking.

Expand for full summary

Summary: The patch enhances the OSV scanner parser in dojo/tools/osv_scanner/parser.py and adds a corresponding unit test in unittests/tools/test_osv_scanner_parser.py to improve vulnerability information extraction and validation.

Security Findings:

  1. Potential Security Information Exposure

    • Detailed vulnerability information added to descriptions
    • Includes source type, package ecosystem, and package PURL
  2. Input Validation Improvements

    • More robust JSON parsing with .get() method
    • Added fallback handling for missing references
    • Reduces potential runtime errors
  3. Mitigation Information Extraction Risks

    • Extracts mitigation versions from different repository types
    • Provides structured upgrade path information
    • Formats mitigation details with clear text
  4. Vulnerability Tracking Considerations

    • Test specifically validates mitigation strategy for known security vulnerability
    • Checks precise ecosystem-specific version upgrade recommendations

View PR in the DryRun Dashboard.

@4b75726169736859
Copy link
Contributor Author

@4b75726169736859
Copy link
Contributor 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
Contributor Author

Could you also fix the ruff linter @4b75726169736859 ?

yes just after my work day

Copy link
Contributor 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

@dogboat
Copy link
Contributor

dogboat commented Mar 4, 2025

@4b75726169736859 This is looking great! Thank you! There are some linter errors, and the corresponding tests might need to be updated -- could you fix those? I think you solved a tricky problem well.

@4b75726169736859
Copy link
Contributor Author

@4b75726169736859 This is looking great! Thank you! There are some linter errors, and the corresponding tests might need to be updated -- could you fix those? I think you solved a tricky problem well.

Of course, I’ll take care of it tomorrow if I have time; otherwise, in the following days.

I also have an issue with version management: to determine which version to fix based on the vulnerable version, I assumed the versions follow the x.x.x format, but they can be different.

This is a topic I need to address.

@valentijnscholten
Copy link
Member

Thank you for working on this @4b75726169736859. I do have some concerns and a possible unpopular opinion.

I've recently done some work in Dependency Track where I had to handle all the different version constraints that the Composer ecosystem supports, such as -dev suffixes and dev- prefixes, versions based on branch names, etc.
See https://getcomposer.org/doc/articles/versions.md. When you look at the code of the Composer CLI it's almost impossible to follow what's going on and which regex matching has what outcome.

And that's just one ecosystem.

The risk is that we add code to Defect Dojo that is not 100% correct and may select the wrong fix version. Wouldn't it be easier and safer to just list all the fixed version ranges and let the user decide to which version he or she wants to update? Everything we add to DD has to be maintained and should have testcases. Sometimes it's better to keep it simple.

@4b75726169736859
Copy link
Contributor Author

Glad to contribute to this project!

I have the same concern. Previously, I made a version that lists all the fixed versions, and it’s already ready.
I could replace the current version of the code with this one.

It’s true that I won’t be able to maintain this indefinitely, as it takes a lot of time.

I would have liked to bring this improvement to this parser.

It’s late here, I will most likely push my second, simplified version tomorrow.

@Maffooch
Copy link
Contributor

Hi @4b75726169736859 I am going to close this out for right now, but please reopen it whenever you are ready 😄

@Maffooch Maffooch closed this Mar 31, 2025
@4b75726169736859
Copy link
Contributor Author

Hi, sorry, I've been very busy...
It slipped my mind.

Here, I've made a few changes and pushed them to the fork.

Is it possible to reopen the pull request or do I need to create a new one?

Here's what it looks like.

Capture d’écran du 2025-04-01 16-11-24

Thanks 😊

@valentijnscholten
Copy link
Member

@4b75726169736859 Thank you. Could you look at the Linting violations and update the unit tests to make them pass?

@4b75726169736859
Copy link
Contributor Author

@4b75726169736859 Thank you. Could you look at the Linting violations and update the unit tests to make them pass?

Sure, no problem
I’ll be able to look at it on Monday ;)

Copy link

dryrunsecurity bot commented Apr 14, 2025

DryRun Security

This pull request contains potential security risks related to information disclosure through detailed vulnerability descriptions and possible URL injection vulnerabilities in reference handling, which could provide attackers with system insights or opportunities for link manipulation.

💭 Unconfirmed Findings (2)
Vulnerability Potential Information Disclosure through Detailed Vulnerability Descriptions
Description Detailed vulnerability descriptions might expose sensitive technical system information, which could provide attackers with additional insights about the system's infrastructure and potential weaknesses.
Vulnerability Expanded Reference Handling with Potential URL Injection Risk
Description Changes in reference handling could introduce URL injection vulnerabilities, primarily due to potentially unsanitized URL references being directly incorporated into findings, which might allow malicious actors to manipulate or inject harmful links.

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

Copy link
Contributor 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.

.

@Maffooch Maffooch closed this Apr 28, 2025
@Maffooch Maffooch reopened this Apr 28, 2025
@Maffooch Maffooch added this to the 2.46.0 milestone Apr 29, 2025
Copy link
Contributor

@mtesauro mtesauro left a comment

Choose a reason for hiding this comment

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

Approved

Copy link
Contributor

@dogboat dogboat left a comment

Choose a reason for hiding this comment

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

Awesome, thank you!

@Maffooch Maffooch merged commit 38700b5 into DefectDojo:dev Apr 30, 2025
77 checks passed
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.

6 participants