API: prevent duplicate saves of taggable entities or when pushing to JIRA#12607
Conversation
889933c to
609f903
Compare
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
🔴 Risk threshold exceeded.This pull request contains multiple security vulnerabilities including debug information exposure, verbose error logging that could aid attackers, and a potential CVE ID manipulation risk in different parts of the application's codebase.
Debug Information Exposure in
|
| Vulnerability | Debug Information Exposure |
|---|---|
| Description | Debug log messages directly log object contents without sanitization, potentially exposing sensitive internal details if debug logging is enabled in production. |
django-DefectDojo/dojo/jira_link/helper.py
Lines 667 to 675 in 7f3d035
Verbose Error Logging in dojo/api_v2/views.py
| Vulnerability | Verbose Error Logging |
|---|---|
| Description | Error messages include the full list of tags and specific invalid tag, which could aid an attacker in enumerating valid tags through targeted error probing. |
django-DefectDojo/dojo/api_v2/views.py
Lines 989 to 1001 in 7f3d035
CVE ID Manipulation in dojo/api_v2/serializers.py
| Vulnerability | CVE ID Manipulation |
|---|---|
| Description | The code sets the CVE field by taking the first vulnerability ID from a user-provided list without validation. This could allow an attacker to manipulate the CVE identifier for a finding by providing a crafted list of vulnerability IDs. |
django-DefectDojo/dojo/api_v2/serializers.py
Lines 1734 to 1765 in 7f3d035
We've notified @mtesauro.
All finding details can be found in the DryRun Security Dashboard.
|
Conflicts have been resolved. A maintainer will review the pull request shortly. |
Maffooch
left a comment
There was a problem hiding this comment.
This is looking really promising! Excellent work here
There was a problem hiding this comment.
I have been manually adding this back in a pinch for so long, but have always forgot to commit it 🥴 thank you for doing so!
| # can we avoid this extra save? the cve has already been set above in validated_data. but there are no tests for this | ||
| # on finding update nothing is done # with vulnerability_ids? |
There was a problem hiding this comment.
Seems like the extra save could be removed since th vulnerability IDs have. dedicated function now
There was a problem hiding this comment.
that extra functions doesn't actually save anything on the finding itself, I think we have to add a small test to ensure a CVE is stored on the finding itself. Unless that field is slated for deprecation?
There was a problem hiding this comment.
I added some tests to make sure vulnerability ids are stored and the cve is populated
There was a problem hiding this comment.
Please clean up those extra comments when you are done with all the manual testing/validation
| "tags" | ||
| ] | ||
| for tag in new_tags.validated_data["tags"]: | ||
| for sub_tag in tagulous.utils.parse_tags(tag): |
There was a problem hiding this comment.
curious why this was needed. Does the tagulous.utils.parse_tags function not work as expected when passed a list vs individual strings?
There was a problem hiding this comment.
IIRC it parses the string repesentation of the list ending up with something like:
- ["tag1"
- "tag2"
- "tag3"]
But it could be that it was needed because I also changed theTagListSerializerFieldto not render the tags as one string. That changes allows us to just let the ModelSerializer serialize the tags without having to pop them and process them ourselves.
Co-authored-by: Cody Maffucci <46459665+Maffooch@users.noreply.github.com>
Maffooch
left a comment
There was a problem hiding this comment.
Excellent work here! These are my favorite kinds of changes to see here 🤗
When creating or updating findings (or other entities that have a
tagsfield), theFinding.save()method was called multiple times. Ultimately thefindingwas saved correctly, but this lead to unnecessary use of resources and could in the future lead to problems if/when the Defect Dojo could be relying more on Django signals such aspost_save().The above was caused by the way the
tagsfields were implemented long ago. I tried to tweak theTaggitSerializerto prevent the duplicate saves from happening, but this lead nowhere. Then I realized I could just tweak ourTagListSerializerto make it work without the "extra"TaggitSerialiser.I also looked at the
from tagulous.contrib.drf import TagSerializer, but that doesn't support the single string with multiple comma separated tags that we re-added support for in #12434Duplicate saves could also be triggered when the finding needed to be pushed to JIRA. This PR also resolves that.
Added some unit tests to make sure all looks well.
I had to rerecord one JIRA related tests around finding groups. Usually this is a red flag, but looking at the test case and asserts I think all is still good. Maybe the old codebase did some duplicagte/unnecessary/idempotent calls to JIRA?
[sc-10686]