-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
fixes reimporter to ensure that risk accepted findings do not get mitigated #9050
Conversation
Contextual Security AnalysisAs DryRun Security performs checks, we’ll summarize them here. You can always dive into the results in the section below for checks.
Chat with your AI-powered Security Buddy by typing Install and configure more repositories at DryRun Security |
So one of the failing tests "test_import_reimport_keep_false_positive_and_out_of_scope" is interesting. Here it becomes obvious there was some kind of "special" treatment going on for existing_findings for which This kind of worked in the cases of However, I always assumed it worked like this: if "do_not_reactivate" == TRUE --> Then Defectdojo is source of truth and Scanner cannot reopen findings. (regardless of false positive, out of scope, risk acceptance) "do_not_reactivate" was introduced here: #6893 but as I read was mostly intended to work-around "triage-less scanners" @Gby56 I agree that if we could define a complete decision table that this would make it easier. |
Good catch with the tests yes, and definitely it's the special case of risk acceptance that highlighted this unclear decision matrix (and poor code reability, but we already knew about that 😄 ) Maybe So my guess, for risk accepted, is:
This is pretty much the same treatment as false positive I'd say, but don't touch the |
The problem here is this code Currently the default behaviour is to just "mitigate" a finding if the scanner sets risk acceptance (or false_p or out of scope). It even sets risk_accepted regardless if "simple risk acceptance" is active it seems. And it does not set mitigated=true (even though Defectdojo always does this in case of " false_p or out of scope" I Think I can come up with a workable structure but need a bit of time to put it to paper, will try and come back with a hierarchy |
I think a decision tree might be better, I realized that a matrix might be a bit overwhelming to navigate it |
dont have a nice way to create this here in this text, so just a screenshot. This is roughly how the logic works now, in: d3d918b |
@coheigea @Gby56 @mtesauro @blakeaowens : this pull request is now ready for review, would appreciate some feedback |
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.
It looks OK to me overall, the logic looks a lot cleaner, before the class was a mess. I don't have the scope to test it right now, but once the patch is applied and released I can test it more thorougjly
See also discussion in DefectDojo#9050
Reminder to: @Gby56 @mtesauro @blakeaowens this pull request is still here, we have been running it on our fork for the last 3 weeks and it seems stable. |
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.
Overall this looks good to me, renaming "items" also helped a whole lot for readability! Thank you for taking the time and testing it out
elif finding.is_mitigated: | ||
if existing_findings: | ||
# existing findings found | ||
existing_finding = existing_findings[0] |
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.
Just wondering if we should log something here for a warning... or if a loop is needed to process all the matched existing findings instead of just the first one ?
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.
Yes I was wondering something similar... For now we could write a debug/log statement. The purpose of this pull request was not to significantly change the behaviour of the reimporter (which this might do). Although I agree that probably this case should be handled somehow, I think this should be handled in a seperate ticket/issue.
Just giving this another bump.... @mtesauro @blakeaowens @Maffooch |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
See also discussion in DefectDojo#9050
See also discussion in DefectDojo#9050
See also discussion in DefectDojo#9050
See also discussion in DefectDojo#9050
Hey everyone, this is still here.... @mtesauro @blakeaowens @Maffooch Willing to fix the conflict if there is still interest to merge this ? |
See also discussion in DefectDojo#9050
hey there, |
Conflicts have been resolved. A maintainer will review the pull request shortly. |
Hi there 👋, @DryRunSecurity here, below is a summary of our analysis and findings.
Note 🔴 Risk threshold exceeded. Adding a reviewer if one is configured in notification list: @mtesauro @grendel513 Change Summary (click to expand)The following is a summary of changes in this pull request made by me, your security buddy 🤖. Note that this summary is auto-generated and not meant to be a definitive list of security issues but rather a helpful summary from a security perspective. Summary: The code changes in this pull request focus on improving the handling of security scan report imports and reimports within the application. The key changes include:
These changes demonstrate a well-designed and feature-rich implementation of security scan report handling, which is a crucial component of a robust application security program. Files Changed:
Powered by DryRun Security |
4213c86
to
484d0c8
Compare
@lme-nca Sorry that this one has gotten lost in the shuffle for so long. Would you mind rebasing this so we can review and approve it? |
DryRun Security SummaryThe pull request focuses on improving the handling of risk-accepted findings during the reimport process and introducing a comprehensive set of unit tests for the import and reimport functionality to ensure the security and integrity of the data being imported. Expand for full summarySummary: The code changes in this pull request focus on improving the handling of risk-accepted findings during the reimport process in the The changes to the The unit tests in the Files Changed:
Code AnalysisWe ran
Riskiness🔴 Risk threshold exceeded. We've notified @mtesauro, @grendel513. |
This tries to improve on the (incomplete) fix introduced here: #7447
Also see the discussion on Slack: https://owasp.slack.com/archives/C014H3ZV9U6/p1700819414409409
and related issue #8797
Previous behaviour:
IF existing findings (false positive, out of scope or risk accepted):
- IGNORE ALL OTHER values of findings from scanner (even if its mitigated) so mitigated findings from scanner that are not mitigated in Defectdojo (but do have one of the above flags would never have been closed)
IF existingFinding.false_p == new_finding.false_p and existingFinding.out_of_scope == new_finding.out_of_scope
and existingFinding.risk_accepted == new_finding.risk_accepted)
- Then:
unchanged_items.append(finding)
- comes from(Add the old finding in the reimporter to the list of unchanged findin… #7447)
ELSE Mitigate the finding incorrectly <--- THE BUG described in this ISSUE:
-- caused by the fact the finding is not added to "unchanged_items.append(finding)"
-- Therefore the following code adds it to the mitigation list
to_mitigate = ( set(original_items) - set(reactivated_items) - set(unchanged_items) )
elIF existing finding IS mitigated
..... // not changed
else (existing finding is not mitigated)
- IF new_finding: false positive, out of scope or risk accepted
-- Close existing findings and take over values of scanner
New behaviour
First IF condition is completely removed, no special treatment needed for this case --> if existing findings (false positive, out of scope or risk accepted):
IF existing finding IS mitigated
..... // not changed
else (existing finding is not mitigated)
simplified logic (removed unnecessary If statement)
--
if not (finding.mitigated and finding.is_mitigated):
this always resolves to TRUE in this else branch!!!-- this changed the indenting here
IF existingFinding.false_p == new_finding.false_p and existingFinding.out_of_scope == new_finding.out_of_scope
and existingFinding.risk_accepted == new_finding.risk_accepted)
- Then dont touch the existing finding, this keeps (Add the old finding in the reimporter to the list of unchanged findin… #7447) alive, however question is if we want this like that ?
IF new_finding: false positive, out of scope or risk accepted
-- Close existing findings and take over values of scanner
ELSE
Do not touch the finding
Overall this is some of the most complicated and unreadable code I have seen so-far in Defectdojo. I would gladly refactor this complete method ( it is way to long and the variable names are terrible), however I dont know if this would fit with the whole Defectdojo 3.0 work ? @mtesauro @Maffooch Let me know if you are open for this and I would gladly work on making this code more digestible.
@coheigea @Gby56 you also both worked on this code, I am open to any suggesting or improvements ?