Skip to content

Commit 112adfe

Browse files
address feedback
1 parent 5ab1c71 commit 112adfe

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

docs/content/en/open_source/contributing/how-to-write-a-parser.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,20 +171,22 @@ Data can have `CVSS` vectors or scores. Don't write your own CVSS score algorith
171171
For parser, we rely on module `cvss`. But we also have a helper method to validate the vector and extract the base score and severity from it.
172172

173173
```python
174+
from dojo.utils import parse_cvss_data
174175
cvss_data = parse_cvss_data("CVSS:3.0/S:C/C:H/I:H/A:N/AV:P/AC:H/PR:H/UI:R/E:H/RL:O/RC:R/CR:H/IR:X/AR:X/MAC:H/MPR:X/MUI:X/MC:L/MA:X")
175176
if cvss_data:
176177
finding.cvssv3 = cvss_data.get("vector")
177178
finding.cvssv3_score = cvss_data.get("score")
178179
finding.severity = cvss_data.get("severity") # if your tool does generate severity
179180
```
180181

181-
If you need more manual processing, you can parse the `CVSS` vector directly.
182+
If you need more manual processing, you can parse the `CVSS3` vector directly.
182183

183184
Example of use:
184185

185186
```python
186-
from dojo.utils import cvss.cvss3 import CVSS3
187187
import cvss.parser
188+
from cvss import CVSS2, CVSS3
189+
188190
vectors = cvss.parser.parse_cvss_from_text("CVSS:3.0/S:C/C:H/I:H/A:N/AV:P/AC:H/PR:H/UI:R/E:H/RL:O/RC:R/CR:H/IR:X/AR:X/MAC:H/MPR:X/MUI:X/MC:L/MA:X")
189191
if len(vectors) > 0 and type(vectors[0]) is CVSS3:
190192
print(vectors[0].severities()) # this is the 3 severities

dojo/models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2707,7 +2707,9 @@ def save(self, dedupe_option=True, rules_option=True, product_grading_option=Tru
27072707

27082708
except Exception as ex:
27092709
logger.warning("Can't compute cvssv3 score for finding id %i. Invalid cvssv3 vector found: '%s'. Exception: %s.", self.id, self.cvssv3, ex)
2710-
# should we set self.cvssv3 to None here to avoid storing invalid vectors? it would also remove invalid vectors on existing findings...
2710+
# remove invalid cvssv3 vector for new findings, or should we just throw a ValidationError?
2711+
if self.pk is None:
2712+
self.cvssv3 = None
27112713

27122714
self.set_hash_code(dedupe_option)
27132715

dojo/tools/npm_audit_7_plus/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import logging
44

55
from dojo.models import Finding
6+
from dojo.utils import parse_cvss_data
67

78
logger = logging.getLogger(__name__)
89

@@ -166,7 +167,6 @@ def get_item(item_node, tree, test):
166167
dojo_finding.cwe = cwe
167168

168169
if (cvssv3 is not None) and (len(cvssv3) > 0):
169-
from dojo.utils import parse_cvss_data
170170
cvss_data = parse_cvss_data(cvssv3)
171171
if cvss_data:
172172
dojo_finding.cvssv3 = cvss_data.get("vector")

0 commit comments

Comments
 (0)