add support for calculating CVSS score from the CVSS vector
re:
Also there is a need for a data migrations to migrate the current CVSS vector to this new approach
CVSSV31, CVSSV31_VECTOR,
say we have two rows with these data:
- scoring_system: CVSSV31_VECTOR value:"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:L/A:H"
- scoring_system: CVSSV31 value: "8.6"
After the migration(s) I would like to see only one record:
- scoring_system: CVSSV31 value: "8.6" scoring_elements: "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:L/A:H"
This is best done in three steps:
- model schema update adding scoring_elements
- data migration that searches and adds or computes the score for CVSS severities and add these to one of the two records 2.1 one way: starting from this record - scoring_system: CVSSV31_VECTOR value:"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:L/A:H" update the record this - update scoring_system: CVSSV31, copy value to value to scoring_elements, compute value 2.2 other way: group pairs of records and merge the two in one of the two records
- data migration to remove the extra record
@ziadhany I pushed these updates:
- merge the latest main branch including handling overlapping migration numbers
- update the the migration(s) to use a bulk update/bulk delete approach
- propagate the use of scoring_elements everywhere including importers, tests, API, etc.
- added some cosmetic improvements to regen tests fixtures easily
The new migration(s) handle all possible duplicates cases this way:
- keep a mapping of severities keyed by the "unique together" values of the model
- keep a set of severity ids to delete
- for each CVSS-related severity:
- if this is a vector:
- update this to move value to scoring elements and compute score in value and use plain cvss scoring system
- if it does not exist in the mapping
- add it to this mapping
- else
- if needed merge/add vector to the existing severity
- mark this severity for deletion
- if this is a vector:
- bulk delete the set of ids
- bulk update severities mapping
I need to test run it on the whole DB to validate this is correct
@ziadhany This is essentially the same approach as yours, but folded in a single migration with bulk updates
LGTM , I tested it with my local database
@ziadhany please add CHANGEOLG for this PR