Skip to content

Parameter confidence is optional and CWE's are not always numerical in GitLab SAST - #3567

Merged
madchap merged 3 commits into
DefectDojo:devfrom
StefanFl:gitlab_confidence
Jan 9, 2021
Merged

madchap merged 3 commits into
DefectDojo:devfrom
StefanFl:gitlab_confidence

Conversation

@StefanFl

Copy link
Copy Markdown
Contributor

GitLab SAST doesn't always set the parameter confidence for a vulnerability, leading to an exception when importing the vulnerabilities.

@StefanFl StefanFl changed the title Parameter confidence is otional in GitLab SAST Parameter confidence is optional in GitLab SAST Dec 30, 2020
@damiencarol

Copy link
Copy Markdown
Contributor

I just reviewed your modification and I have 2 comments here:

  1. as the file is loaded with json.load() you have dictionaries for the items.
    It means that you should use something like that to manage optional attributes:
scanner_confidence = vuln.get('confidence'], 'Unknown')

It seems that the default value is Unknown
2) the current code doesn't make any sense.

scanner_confidence = Finding.get_number_severity(vuln['confidence'])

see here
the function get_number_severity has no link to the confidence. For me it is a bug.

@damiencarol

Copy link
Copy Markdown
Contributor

Also, @StefanFl could you add another report and keep the old one? Could be good to have the report that makes you exceptions.
If you are ok to provide your report, keep in mind that it's an open-source project so remove the personal details in the report.
Thanks in advance.

@damiencarol damiencarol left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my previous comments. Some modifications could be different.

Comment thread dojo/tools/gitlab_sast/parser.py Outdated
scanner_confidence = Finding.get_number_severity(vuln['confidence'])
scanner_confidence = None
if 'confidence' in vuln:
scanner_confidence = Finding.get_number_severity(vuln['confidence'])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
scanner_confidence = Finding.get_number_severity(vuln['confidence'])
scanner_confidence = vuln.get('confidence', 'Unknown')

@damiencarol

Copy link
Copy Markdown
Contributor

@StefanFl does this issue is linked to #3534?

@StefanFl

Copy link
Copy Markdown
Contributor Author

@damiencarol GitLab has 2 different scanners. GitLab SAST is static code analysis (the parser of this PR), while the PR you have referenced parses the results of the GitLab Dependency Scanner. File format for these 2 scanners seems to be pretty similar.

Thank you for the review, will change the files according to your suggestions.

@StefanFl

Copy link
Copy Markdown
Contributor Author

Interesting one, it was definitely a bug. GitLab SAST can produce a confidence, but the values (search for confidence in https://docs.gitlab.com/ce/development/integrations/secure.html) need to be mapped to the values understood by DefectDojo (see Finding.get_scanner_confidence_text()).

The new report is an amended excerpt from findings for the OWASP Juice Shop, I think this should be allowed.

@StefanFl

Copy link
Copy Markdown
Contributor Author

Please wait with the review, I think there is another problem with these reports

@damiencarol

Copy link
Copy Markdown
Contributor

Take your time and happy new year!
For the record:
https://docs.gitlab.com/ce/development/integrations/secure.html#severity-and-confidence

The confidence ranges from Low to Confirmed, but it can also be Unknown, Experimental or even Ignore if the vulnerability is to be ignored. Valid values are: Ignore, Unknown, Experimental, Low, Medium, High, or Confirmed

Unknown values means that data is unavailable to determine it’s actual value. Therefore, it may be high, medium, or low, and needs to be investigated. We have provided a chart of the available SAST Analyzers and what data is currently available.

@StefanFl

Copy link
Copy Markdown
Contributor Author

All values are mapped apart from `

  • Unkown where the confidence is set to None
  • Ignore where the confidence is set to None as well, because there is no respective value in DefectDojo

For the others see the method get_confidence_numeric(argument) in the parser

@StefanFl StefanFl changed the title Parameter confidence is optional in GitLab SAST Parameter confidence is optional and CWE's are not always numerical in GitLab SAST Dec 31, 2020
@StefanFl

StefanFl commented Dec 31, 2020 •

Copy link
Copy Markdown
Contributor Author

A further test showed, that GitLab sometimes writes non-numerical CWE's which can not be stored in the database. There is a fix for it as well now including a new test case.

Please re-review the whole PR, thank you.

@damiencarol damiencarol left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, high quality modification, this will make Gitlab SAST parser more robust!

One minor feedback, you could have used the feature of subtests to check the items in the unit tests: https://docs.python.org/3/library/unittest.html#distinguishing-test-iterations-using-subtests

@damiencarol

Copy link
Copy Markdown
Contributor

@valentijnscholten @madchap it's ready for review.

@StefanFl StefanFl closed this Jan 5, 2021
@StefanFl
StefanFl deleted the gitlab_confidence branch January 5, 2021 17:45
@damiencarol

Copy link
Copy Markdown
Contributor

@StefanFl why did you closed this PR ?

@StefanFl
StefanFl restored the gitlab_confidence branch January 6, 2021 18:34
@StefanFl StefanFl reopened this Jan 6, 2021
@StefanFl

StefanFl commented Jan 6, 2021

Copy link
Copy Markdown
Contributor Author

Oops, that wasn't intended, thanks @damiencarol for notifying me.

@madchap madchap added the bugfix label Jan 9, 2021

@madchap madchap left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good job @StefanFl and thanks for the tight review @damiencarol :)

@madchap madchap mentioned this pull request Jan 19, 2021
@StefanFl
StefanFl deleted the gitlab_confidence branch May 10, 2021 04:35
9alexx3 pushed a commit to 9alexx3/django-DefectDojo that referenced this pull request Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants