Skip to content
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

dissallow already linked issue #11298

Open
wants to merge 1 commit into
base: bugfix
Choose a base branch
from
Open

Conversation

hblankenship
Copy link
Collaborator

[sc-5525]

Fixes #9930

When using the jira_finding_mappings API endpoint, trying to update a finding's Jira mapping with a Jira issue that is already assigned to another finding will now raise a validation error.

@github-actions github-actions bot added the apiv2 label Nov 20, 2024
Copy link

DryRun Security Summary

The pull request focuses on improving the handling of JIRA issue linking in the Defect Dojo application by introducing a new function to check if a finding is already linked to a JIRA issue and using it in the JIRAIssueSerializer class to prevent the creation of duplicate JIRA issues, which is a positive step in maintaining data integrity and improving the overall security and traceability of the application.

Expand for full summary

Summary:

The code changes in this pull request focus on improving the handling of JIRA issue linking in the Defect Dojo application. The changes introduce a new function, jira_already_linked(), in the dojo/jira_link/helper.py file, which checks if a finding is already linked to a JIRA issue. This function is then used in the JIRAIssueSerializer class in the dojo/api_v2/serializers.py file to validate that a JIRA issue is not already linked to a finding before creating a new one.

These changes are a positive step in maintaining data integrity and preventing duplicate JIRA issues from being created, which could lead to confusion and potential security issues. By ensuring that JIRA issues are uniquely linked to findings, the application can improve its overall security and traceability. Overall, these code changes appear to be a reasonable and appropriate security-focused update to the Defect Dojo application.

Files Changed:

  1. dojo/jira_link/helper.py:

    • Added a new function called jira_already_linked() that checks if a finding is already linked to a JIRA issue.
    • The purpose of this function is to prevent duplicate JIRA issues from being created for a finding.
  2. dojo/api_v2/serializers.py:

    • Updated the JIRAIssueSerializer class to include a validation check that calls the jira_helper.jira_already_linked() function.
    • This validation ensures that a JIRA issue is not already linked to a finding before creating a new one.
    • If a linked finding is found, the serializer will raise a ValidationError with a message indicating that the JIRA issue is already linked to another finding.

Code Analysis

We ran 9 analyzers against 2 files and 0 analyzers had findings. 9 analyzers had no findings.

Riskiness

🟢 Risk threshold not exceeded.

View PR in the DryRun Dashboard.

Copy link
Contributor

@Maffooch Maffooch left a comment

Choose a reason for hiding this comment

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

Updated the function to return the whole finding rather than just the ID. It could be useful in the future

Comment on lines +1429 to +1437
def jira_already_linked(finding, jira_issue_key, jira_id):
jira_issues = JIRA_Issue.objects.filter(jira_id=jira_id, jira_key=jira_issue_key).exclude(engagement__isnull=False)
jira_issues = jira_issues.exclude(finding=finding)

result = 0
if len(jira_issues) > 0:
result = jira_issues[0].finding_id

return result
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def jira_already_linked(finding, jira_issue_key, jira_id):
jira_issues = JIRA_Issue.objects.filter(jira_id=jira_id, jira_key=jira_issue_key).exclude(engagement__isnull=False)
jira_issues = jira_issues.exclude(finding=finding)
result = 0
if len(jira_issues) > 0:
result = jira_issues[0].finding_id
return result
def jira_already_linked(finding, jira_issue_key, jira_id) -> Finding | None:
jira_issues = JIRA_Issue.objects.filter(jira_id=jira_id, jira_key=jira_issue_key).exclude(engagement__isnull=False)
jira_issues = jira_issues.exclude(finding=finding)
return jira_issues.first()

Comment on lines +1291 to +1294
linked_finding = jira_helper.jira_already_linked(finding, data.get("jira_key"), data.get("jira_id"))
if linked_finding:
msg = "JIRA issue " + data.get("jira_key") + " already linked to " + reverse("view_finding", args=(linked_finding,))
raise serializers.ValidationError(msg)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
linked_finding = jira_helper.jira_already_linked(finding, data.get("jira_key"), data.get("jira_id"))
if linked_finding:
msg = "JIRA issue " + data.get("jira_key") + " already linked to " + reverse("view_finding", args=(linked_finding,))
raise serializers.ValidationError(msg)
if (linked_finding := jira_helper.jira_already_linked(finding, data.get("jira_key"), data.get("jira_id"))) is not None:
msg = "JIRA issue " + data.get("jira_key") + " already linked to " + reverse("view_finding", args=(linked_finding.id,))
raise serializers.ValidationError(msg)

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.

2 participants