Re-add writable directory check for target path#701
Closed
fadrian06 wants to merge 1 commit into
Closed
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts validation order in UploadedFile::moveTo() to perform target-path traversal validation before checking whether the destination directory is writable, aiming to improve security and error handling.
Changes:
- Reordered the target directory writability check to run after the directory traversal check in
moveTo().
Comment on lines
+139
to
+141
| if (is_writeable(dirname($targetPath)) === false) { | ||
| throw new Exception('Target directory is not writable'); | ||
| } |
| } | ||
|
|
||
| // Prevent absolute paths (basic check for Unix/Windows) | ||
| if ($targetPath[0] === '/' || (strlen($targetPath) > 1 && $targetPath[1] === ':')) { |
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.
This pull request makes a small but important change to the
moveTomethod inflight/net/UploadedFile.php. The check for whether the target directory is writable has been moved to occur after the check for directory traversal in the target path. This helps ensure that path validation is performed before checking permissions, improving security and error handling.moveTo, the check for writable target directory now occurs after verifying that the target path does not contain directory traversal sequences, reducing the risk of improper permission checks on unsafe paths.