Skip to content

Improve cvssv3 validation #12440

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

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

Conversation

valentijnscholten
Copy link
Member

@valentijnscholten valentijnscholten commented May 13, 2025

Although it's not fully clear "what the problem is" reported in #8264 , we want to stop using the regex for validation and use the cvss library in a validator. This PR updates the validator on the model and updates the test cases to reflect the new behaviour. The new behaviour is better:

  • When saving via API or UI invalid vectors are recjted. (2 vectors, v3 vectors without a prefix, v3 vectors with a trailing slash, v4 vectors, ...)
  • When Finding.save() is called, no validation is perfrmed by Django. So we have make sure the parsers only store valid vectors.

I updated the parsers that did not yet follow the guidelines in docs/content/en/open_source/contributing/how-to-write-a-parser.md. I considered:

  • adding a set_data_from_cvss_string(...) to the Finding model
  • adding code to Finding.save() to validate/parse the vector string

But in the end I went for a helper method in dojo.utils to parse the CVSS vector. This way we have the parsing logic in one central place and the parsers can decide which of the 3 parsed fields they want to use on the model (vector, score, severity). The logic is also failsafe, invalid vectors result in empty cvss fields but won't cause the import to fail.

Remaining questions:

  • Do we want to keep the logic in place in Finding.save() that sets (overwrites) the cvssv3_score if a valid vector is set? (I think for now YES)
  • What to we do when Finding.save() encounters an invalid vector in cvssv3. Should we clear the vector before saving? (I think for now NO)
  • Do we want to make sure all parsers use the same/new parse function? (I think for now NO as long as they parse the vector correctly)

Risks:

  • The parsers are fail-safe, but users submitting invalid CVSSv3 vectors through the API may run into HTTP_400 validation errors. But I'm not sure if that is a bad thing?

Feedback welcome. I also think this is a nice preparation for when we want to support CVSS4 vectors.

@github-actions github-actions bot added apiv2 unittests New Migration Adding a new migration file. Take care when merging. parser labels May 13, 2025
Copy link
Contributor

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

Copy link
Contributor

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

@valentijnscholten valentijnscholten requested a review from kiblik May 16, 2025 21:08
@valentijnscholten valentijnscholten marked this pull request as ready for review May 16, 2025 21:09
Copy link

dryrunsecurity bot commented May 16, 2025

DryRun Security

This pull request introduces potential security risks related to CVSS vector parsing, logging, and input validation across multiple files, with concerns about incomplete data sanitization, reduced logging visibility, and potential exposure of sensitive vulnerability information.

💭 Unconfirmed Findings (9)
Vulnerability Potential Information Disclosure via Logging
Description In dojo/models.py, changing logging from error to warning reduces visibility of potential security issues, which could lead to missed critical information.
Vulnerability Potential Incomplete CVSS Validation
Description In dojo/models.py, the custom validator might introduce less strict validation rules compared to the original regex, potentially allowing invalid CVSS vectors.
Vulnerability Potential Data Sanitization Issue
Description In dojo/models.py, the new parse_cvss_data() function might have incomplete input validation, risking potential data manipulation.
Vulnerability Potential Information Disclosure through CVSS Parsing
Description In dojo/utils.py, the new CVSS parsing function could expose sensitive vulnerability scoring information.
Vulnerability Removal of Tag Validation Logic
Description In dojo/utils.py, elimination of previous input validation for tags could introduce sanitization risks and potential data integrity issues.
Vulnerability Potential Logging of Sensitive Input
Description In dojo/validators.py, error logging might expose sensitive vulnerability vector information.
Vulnerability Broad Exception Handling
Description In dojo/validators.py, the configurable exception class could allow manipulation of error handling, potentially bypassing security controls.
Vulnerability Potential Lack of Input Validation for CVSSv3 Vectors
Description In unittests/test_finding_model.py, saving vectors without validation could lead to data integrity issues and potential misrepresentation of vulnerability severity.
Vulnerability Insufficient CVSS Vector Validation
Description In unittests/test_rest_framework.py, previously allowed storing invalid CVSS vectors, potentially misrepresenting vulnerability severity and compromising risk assessment.

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

@valentijnscholten valentijnscholten changed the title cvssv3 validation Improve cvssv3 validation May 16, 2025
Copy link
Contributor

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

Copy link
Contributor

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

@valentijnscholten valentijnscholten added this to the 2.47.0 milestone May 28, 2025
Copy link
Contributor

@Maffooch Maffooch left a comment

Choose a reason for hiding this comment

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

This is looking really good - only a couple questions/nits

dojo/models.py Outdated
except Exception as ex:
logger.error("Can't compute cvssv3 score for finding id %i. Invalid cvssv3 vector found: '%s'. Exception: %s", self.id, self.cvssv3, ex)
logger.warning("Can't compute cvssv3 score for finding id %i. Invalid cvssv3 vector found: '%s'. Exception: %s.", self.id, self.cvssv3, ex)
# should we set self.cvssv3 to None here to avoid storing invalid vectors? it would also remove invalid vectors on existing findings...
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should remove invalid vectors, but only if the id is None before the finding is saved. That allows us to prevent the issue from spreading even further without implications for existing data

Copy link
Member Author

Choose a reason for hiding this comment

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

addressed this, but maybe we should just throw a ValidationError? That is what will happen in the future if we implement better validation support for Findings in general via clean.

Copy link
Contributor

Choose a reason for hiding this comment

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

actually, I think the validator will do this already, as its called before the save method is, right?

@github-actions github-actions bot removed the New Migration Adding a new migration file. Take care when merging. label May 29, 2025
@github-actions github-actions bot added the New Migration Adding a new migration file. Take care when merging. label May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apiv2 docs integration_tests New Migration Adding a new migration file. Take care when merging. parser unittests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants