-
Notifications
You must be signed in to change notification settings - Fork 18
WIP: Include in Firehose models multipe CWEs #33
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,7 +121,7 @@ | |
| http://cwe.mitre.org/data/definitions/131.html | ||
| --> | ||
| <attribute name="cwe"> | ||
| <data type="integer"/> | ||
| <data type="string"/> | ||
| </attribute> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As noted above, this probably should be something like: or somesuch. |
||
| </optional> | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,6 +68,8 @@ def from_json(self, jsonobj): | |
| return jsonobj | ||
| if self.type == float: | ||
| return jsonobj | ||
| if self.type == list: | ||
| return jsonobj | ||
| return self.resolve_type().from_json(jsonobj) | ||
|
|
||
| def to_json(obj): | ||
|
|
@@ -233,7 +235,7 @@ def from_json(cls, jsonobj): | |
| raise TypeError('unknown type: %r' % jsonobj['type']) | ||
|
|
||
| class Issue(Result): | ||
| attrs = [Attribute('cwe', int, nullable=True), | ||
| attrs = [Attribute('cwe', list, nullable=True), | ||
| Attribute('testid', _string_type, nullable=True), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "cwe" should probably be replaced by "externalids" or somesuch, for external IDs. (Not sure of the name). It would be a list of instances of some base class, with CWE being a subclass. |
||
| Attribute('location', 'Location'), | ||
| Attribute('message', 'Message'), | ||
|
|
@@ -251,8 +253,15 @@ def __init__(self, | |
| trace, | ||
| severity=None, | ||
| customfields=None): | ||
| cwes = [] | ||
| if cwe is not None: | ||
| assert isinstance(cwe, int) | ||
| if not isinstance(cwe, int): | ||
| cwes = cwe | ||
| assert isinstance(cwes, list) | ||
| for cwe in cwes: | ||
| assert isinstance(cwe, int) | ||
| else: | ||
| assert isinstance(cwe, int) | ||
| if testid is not None: | ||
| assert isinstance(testid, _string_type) | ||
| assert isinstance(location, Location) | ||
|
|
@@ -265,7 +274,7 @@ def __init__(self, | |
| assert isinstance(severity, _string_type) | ||
| if customfields is not None: | ||
| assert isinstance(customfields, CustomFields) | ||
| self.cwe = cwe | ||
| self.cwe = cwes | ||
| self.testid = testid | ||
| self.location = location | ||
| self.message = message | ||
|
|
@@ -277,8 +286,11 @@ def __init__(self, | |
| @classmethod | ||
| def from_xml(cls, node): | ||
| cwe = node.get('cwe') | ||
| if cwe is not None: | ||
| cwe = int(cwe) | ||
| cwe_list = [] | ||
| if cwe is not None and cwe is not "": | ||
| cwes = cwe.split(',') | ||
| for cwe in cwes: | ||
| cwe_list.append(int(cwe)) | ||
| testid = node.get('test-id') | ||
| location = Location.from_xml(node.find('location')) | ||
| message = Message.from_xml(node.find('message')) | ||
|
|
@@ -298,12 +310,18 @@ def from_xml(cls, node): | |
| customfields = CustomFields.from_xml(customfields_node) | ||
| else: | ||
| customfields = None | ||
| return Issue(cwe, testid, location, message, notes, trace, severity, customfields) | ||
| return Issue(cwe_list, testid, location, message, notes, trace, severity, customfields) | ||
|
|
||
| def to_xml(self): | ||
| node = ET.Element('issue') | ||
| if self.cwe is not None: | ||
| node.set('cwe', str(self.cwe)) | ||
| if isinstance(self.cwe, list): | ||
| cwe_list = "" | ||
| for cwe in self.cwe: | ||
| cwe_list += ',' + str(cwe) | ||
| node.set('cwe', str(cwe_list[1::])) | ||
| else: | ||
| node.set('cwe', str(self.cwe)) | ||
| if self.testid is not None: | ||
| node.set('test-id', str(self.testid)) | ||
| node.append(self.message.to_xml()) | ||
|
|
@@ -339,7 +357,9 @@ def diagnostic(filename, line, column, kind, msg): | |
| % (self.location.file.givenpath, | ||
| self.location.function.name)) | ||
| if self.cwe: | ||
| cwetext = ' [%s]' % self.get_cwe_str() | ||
| if isinstance(self.cwe, list): | ||
| cwetext = [] | ||
| cwetext = self.get_cwe_str() | ||
| else: | ||
| cwetext = '' | ||
| diagnostic(filename=self.location.file.givenpath, | ||
|
|
@@ -379,12 +399,27 @@ def accept(self, visitor): | |
| self.trace.accept(visitor) | ||
|
|
||
| def get_cwe_str(self): | ||
| cwe_list_str = [] | ||
| if self.cwe is not None: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would become a method of a new CWE class. |
||
| return 'CWE-%i' % self.cwe | ||
| if isinstance(self.cwe, list): | ||
| for cwe in self.cwe: | ||
| cwe_list_str.append('CWE-%i' % int(cwe)) | ||
| else: | ||
| cwe_list_str.append('CWE-%i' % int(self.cwe)) | ||
| return cwe_list_str | ||
|
|
||
|
|
||
| def get_cwe_url(self): | ||
| cwe_list_str = [] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Likewise. |
||
| if self.cwe is not None: | ||
| return 'http://cwe.mitre.org/data/definitions/%i.html' % self.cwe | ||
| if isinstance(self.cwe, list): | ||
| for cwe in self.cwe: | ||
| cwe_list_str.append('http://cwe.mitre.org/data/definitions/%i.html' % cwe) | ||
| return cwe_list_str | ||
| else: | ||
| cwe_list_str.append('http://cwe.mitre.org/data/definitions/%i.html' % self.cwe) | ||
| return cwe_list_str | ||
|
|
||
|
|
||
| class Failure(Result): | ||
| attrs = [Attribute('failureid', _string_type, nullable=True), | ||
|
|
||
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.
Thanks for posting this.
Could you please add a fresh example e.g. taken from the flawfinder example you posted a screenshot of?
I'm not keen on having comma-separated values in the XML; I think it would be cleaner to introduce elements for these IDs, so that client code doesn't have to parse the attributes. Instead we should add a new zero-or-more child element to the XML schema.
We might want to support other categorization schemes - the readme.rst talks about: