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

Hyades backport: Preprocess CWE dictionary #3284

Merged
merged 3 commits into from
Dec 9, 2023

Conversation

nscuro
Copy link
Member

@nscuro nscuro commented Dec 8, 2023

Description

The current setup is parsing the CWE dictionary XML at runtime and persisting it to the database (CweImporter), just to load it from the database again into memory (CweResolver). Both CweImporter and CweResolver end up holding the entire CWE dictionary in static Maps, which is unnecessary.

CWEs are synchronized with the database on startup, where each CWE is processed in a database transaction. That is over 1400 transactions before anything meaningful is done.

As of v4.5 (#1467), CWEs are stored as serialized list in the VULNERABILITY table. The CWE table is thus not required anymore, as nothing is referring to it. Lookups can be served immediately from in-memory maps.

With this change, the CWE dictionary is pre-processed with a Python script. It generates a Java class that holds all entries in a static LinkedHashMap. Persistence logic around CWEs is removed, and the CWE table is dropped.

This is a backport from Hyades.

Addressed Issue

N/A

Additional Details

N/A

Checklist

  • I have read and understand the contributing guidelines
  • This PR fixes a defect, and I have provided tests to verify that the fix is effective
  • This PR implements an enhancement, and I have provided tests to verify that it works as intended
  • This PR introduces changes to the database model, and I have added corresponding update logic
  • This PR introduces new or alters existing behavior, and I have updated the documentation accordingly

The current setup is parsing the CWE dictionary XML at runtime and persisting it to the database (`CweImporter`), just to load it from the database again into memory (`CweResolver`). Both `CweImporter` and `CweResolver` end up holding the entire CWE dictionary in static `Map`s, which is unnecessary.

CWEs are synchronized with the database on startup, where each CWE is processed in a database transaction. That is over 1400 transactions before anything meaningful is done.

As of v4.5 (DependencyTrack#1467), CWEs are stored as serialized list in the `VULNERABILITY` table. The `CWE` table is thus not required anymore, as nothing is referring to it. Lookups can be served immediately from in-memory maps.

With this change, the CWE dictionary is pre-processed with a Python script. It generates a Java class that holds all entries in a static `LinkedHashMap`. Persistence logic around CWEs is removed, and the `CWE` table is dropped.

This is a backport from Hyades.

Signed-off-by: nscuro <nscuro@protonmail.com>
@nscuro nscuro added the enhancement New feature or request label Dec 8, 2023
@nscuro nscuro added this to the 4.11 milestone Dec 8, 2023
Signed-off-by: nscuro <nscuro@protonmail.com>
Signed-off-by: nscuro <nscuro@protonmail.com>
@nscuro nscuro merged commit 6e1fbf5 into DependencyTrack:master Dec 9, 2023
8 of 9 checks passed
@nscuro nscuro deleted the cwe-cleanup branch December 9, 2023 18:07
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant