Fix 9 security vulnerabilities found in audit#366
Merged
Conversation
- Fix path traversal in file uploads: sanitize filenames to basename, reject ".." and "." when generate_random_filename_on_upload is off - Fix TOCTOU race in file_response: replace stat-then-open with open-then-fstat; add O_NOFOLLOW on non-Windows - Fix FD leaks in file_response: close fd on lseek failure and zero-size file path - Fix NULL deref in answer_to_connection: check conninfo before use - Fix uninitialized _file_size in file_info (default to 0) - Fix auth skip path bypass: normalize path (resolve ".." segments) before comparing against skip paths - Fix free() vs MHD_free() for digest auth username - Fix unchecked write error during file upload
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #366 +/- ##
==========================================
- Coverage 68.70% 67.93% -0.78%
==========================================
Files 28 28
Lines 1601 1634 +33
Branches 651 672 +21
==========================================
+ Hits 1100 1110 +10
- Misses 58 64 +6
- Partials 443 460 +17
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
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
Fixes 9 security vulnerabilities identified in a security audit, ranging from HIGH to LOW severity:
generate_random_filename_on_uploadis disabled, a craftedfilenamefield (e.g.../escape) could write files outside the upload directory. Addedsanitize_upload_filename()that extracts the basename and rejects.,.., and empty names.stat()-then-open()withopen()-then-fstat()to eliminate the race window. AddedO_NOFOLLOWon non-Windows to prevent symlink following.file_response::get_raw_response()leaked the fd whenlseek()returned -1. Now closes fd before returning nullptr.MHD_get_connection_info()can return nullptr; added null check before dereferencingconninfo->connect_fdfor TCP_NODELAY._file_size—file_info::_file_sizewas uninitialized in the default constructor. Now zero-initialized.should_skip_auth()now normalizes paths (resolves..and.segments) before comparing, preventing bypass via/public/../protected.free()vsMHD_free()— Digest auth username was freed withfree()instead ofMHD_free(). Fixed to use the correct deallocator.!good()check afterwrite(), returningMHD_NOon failure.Test plan
make check)../escape) is rejected, no file created outside upload dirsome/path/myfile.txt) is sanitized to basename only/public/../protectedrequires auth (not bypassed via..traversal)