Skip to content

Commit a2f1f98

Browse files
address feedback
1 parent ac4e182 commit a2f1f98

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

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
@@ -172,20 +172,22 @@ Data can have `CVSS` vectors or scores. Don't write your own CVSS score algorith
172172
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.
173173

174174
```python
175+
from dojo.utils import parse_cvss_data
175176
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")
176177
if cvss_data:
177178
finding.cvssv3 = cvss_data.get("vector")
178179
finding.cvssv3_score = cvss_data.get("score")
179180
finding.severity = cvss_data.get("severity") # if your tool does generate severity
180181
```
181182

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

184185
Example of use:
185186

186187
```python
187-
from dojo.utils import cvss.cvss3 import CVSS3
188188
import cvss.parser
189+
from cvss import CVSS2, CVSS3
190+
189191
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")
190192
if len(vectors) > 0 and type(vectors[0]) is CVSS3:
191193
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)