-
Notifications
You must be signed in to change notification settings - Fork 30
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
Add option to dump minimal JSON #36
Conversation
@@ -196,6 +196,20 @@ def get_value(self, abbreviation): | |||
result = METRICS_VALUES[abbreviation][string_value] | |||
return result | |||
|
|||
def is_environmental_used(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably could be optimized:
def is_environmental_used(self):
for metric in ENVIRONMENTAL_METRICS:
if metric in self.original_metrics:
return True
return False
Applies to the other function also.
@skontar Hmm, looking this it's not actually clear to me as to why the optional "modified" metrics are being set to their non-modified equivalents. If my vector has AV:N, I don't think that implies that it should also have MAV:N, no? If not provided, I would assume MAV would be set to X. As far as this PR goes, I think a nicer solution would be simply constructing the JSON from the fields that are defined in the |
@mprpic do I understand correctly that the original implementation is not clear to you? I can look at it next week to see why it was implemented the way it is. I do not remember anymore. |
@skontar Yea, basically I'm curious as to why this: def add_missing_optional(self):
"""
Adds missing optional parameters, so they match the mandatory ones. Original metrics are
also stored, as they may be used for printing back the minimal vector.
"""
self.original_metrics = copy.copy(self.metrics)
for abbreviation in ['MAV', 'MAC', 'MPR', 'MUI', 'MC', 'MI', 'MA']:
if abbreviation not in self.metrics or self.metrics[abbreviation] == 'X':
self.metrics[abbreviation] = self.metrics[abbreviation[1:]] is not simply this: def add_missing_optional(self):
self.original_metrics = copy.copy(self.metrics)
for abbreviation in ['MAV', 'MAC', 'MPR', 'MUI', 'MC', 'MI', 'MA']:
if abbreviation not in self.metrics:
self.metrics[abbreviation] == 'X' The doc string even notes |
@mprpic I think that There are |
@mprpic Seems like |
@skontar Yep, I agree that the json function should be updated to use original metrics; I noted that in my comment above (#36 (comment)). I'm still not clear though what |
I think that the equation/math which uses modified metrics does math based on "effective" value of those modified metrics. That "effective" value is basically "if the modified metric is defined, use that, otherwise use non-modified value".
For the math purpose they cannot really be not defined. Not defined effectively means the same as non-modified variant. |
|
A ha! That is the verbiage I was looking for. Perhaps we could add a reference to this in the doc string to make it clearer for future users. |
@dim0x69 if user did not supply specific modified metric, would you prefer to not see it in the JSON at all or is "Not Defined (X)" fine for your purpose? I am thinking that using |
Just fyi, I submitted a separate PR (#39) that cleans up the commits here based on the feedback submitted here, and adds the same logic to CVSS2. I think we can close this one if the other one is merged. |
Hi,
currently CVSS3.as_json() adds metrics to the JSON representation of the vector, which were not part of the user-supplied vector. For example, if no "Modified Attack Vector" is supplied in the vector, the JSON will contain the MAV property with the value from AV.
This PR adds the parameter "minimal=True" to "CVSS3.as_json", which allows to dump only a minimal JSON.