Security: Path Traversal in File Cleanup Command#2135
Closed
tomaioo wants to merge 1 commit into
Closed
Conversation
In `accounts/management/commands/clean_old_tmp_upload_files.py`, the code concatenates `settings.FILE_UPLOAD_TEMP_DIR` with `f` using simple string concatenation (`settings.FILE_UPLOAD_TEMP_DIR + f`). If `settings.FILE_UPLOAD_TEMP_DIR` does not end with a path separator, or if an attacker can influence the directory contents, this could lead to path traversal. More critically, the code iterates over all files in the directory and deletes them without proper validation, which could be exploited if the directory is not properly secured. Signed-off-by: tomaioo <203048277+tomaioo@users.noreply.github.com>
Open
Member
|
Thanks for the report! We don't consider this a high severity issue, as it's an admin-only command and the configuration is set correctly so that it's not an issue in our environment. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Security: Path Traversal in File Cleanup Command
Problem
Severity:
High| File:accounts/management/commands/clean_old_tmp_upload_files.py:L37In
accounts/management/commands/clean_old_tmp_upload_files.py, the code concatenatessettings.FILE_UPLOAD_TEMP_DIRwithfusing simple string concatenation (settings.FILE_UPLOAD_TEMP_DIR + f). Ifsettings.FILE_UPLOAD_TEMP_DIRdoes not end with a path separator, or if an attacker can influence the directory contents, this could lead to path traversal. More critically, the code iterates over all files in the directory and deletes them without proper validation, which could be exploited if the directory is not properly secured.Solution
Use
os.path.join()instead of string concatenation for path construction. Add validation to ensure files are within the expected directory usingos.path.realpath()or similar. Consider usingpathlib.Pathfor safer path handling.Changes
accounts/management/commands/clean_old_tmp_upload_files.py(modified)