-
Notifications
You must be signed in to change notification settings - Fork 0
[Security] Fix CodeQL alert #28: Uncontrolled data used in path expression #96
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,10 @@ | |
| def download_file(): | ||
| filename = request.args.get('file') | ||
|
|
||
| file_path = os.path.join('/var/www/uploads/', filename) | ||
| base_dir = '/var/www/uploads/' | ||
| file_path = os.path.realpath(os.path.join(base_dir, filename)) | ||
| if not file_path.startswith(os.path.realpath(base_dir)): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Path traversal check bypassable via sibling directory namesHigh Severity The |
||
| return 'Access denied', 403 | ||
| return send_file(file_path) | ||
|
|
||
| @app.route('/read') | ||
|
|
||


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.
🔴 Path traversal fix is bypassable due to missing trailing separator in
startswithcheckThe
startswithcheck on line 12 is vulnerable to a directory-prefix bypass.os.path.realpath('/var/www/uploads/')strips the trailing slash, returning/var/www/uploads. An attacker can supplyfilename=../uploads_evil/secret.txt, which resolves to/var/www/uploads_evil/secret.txt. This passes thestartswith('/var/www/uploads')check because the string/var/www/uploads_evil/...does start with/var/www/uploads. The fix must appendos.septo the resolved base directory to ensure only true children of the base directory are matched.Was this helpful? React with 👍 or 👎 to provide feedback.