Refactor async_delete mapping and filter logic#13908
Conversation
|
This pull request contains a race condition: the code re-initializes the task_results list inside the loop over model types, so only the last batch of asynchronous Celery delete tasks is waited on, allowing the parent object to be deleted before earlier child deletions complete and potentially leaving orphaned records.
Race Condition in Asynchronous Deletion in
|
| Vulnerability | Race Condition in Asynchronous Deletion |
|---|---|
| Description | The task_results list is re-initialized within the for model_info in model_list: loop. This means that for each type of child object being processed (e.g., Endpoints, Findings, Tests, Engagements related to a Product_Type), the task_results list is cleared. Consequently, the subsequent loop for task_result in task_results: will only wait for the asynchronous delete_chunk tasks related to the last model_info processed. The delete_chunk calls are indeed asynchronous Celery tasks, as indicated by the @app.task decorator on delete_chunk and the hasattr(result, "get") check, which is characteristic of Celery's AsyncResult objects. This leads to a race condition where the main parent object (obj) is deleted by self.delete_chunk([obj]) before all its dependent child objects (from previous model_info iterations) have been fully processed and deleted, potentially resulting in orphaned records in the database. |
django-DefectDojo/dojo/utils.py
Lines 2073 to 2076 in 4821353
All finding details can be found in the DryRun Security Dashboard.
| for task_result in task_results: | ||
| task_result.get(timeout=300) # 5 minute timeout per chunk |
There was a problem hiding this comment.
iirc my intention was to move this to the left. looks like instead i moved the lines below to the right.
valentijnscholten
left a comment
There was a problem hiding this comment.
Looks OK, but we may have to consider not doing it in parallel at considering the locking issues it's causing.
Improve clarity and accuracy of the async_delete mapping and filter logic by updating the query parameters and ensuring proper ID usage throughout the deletion process.
Fixes stack trace