-
Notifications
You must be signed in to change notification settings - Fork 18
1110 strip directory traversal instructions from volume and file paths #1334
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: master
Are you sure you want to change the base?
1110 strip directory traversal instructions from volume and file paths #1334
Conversation
…ip-directory-traversal-instructions-from-volume-and-file-paths
| return false; | ||
| } | ||
|
|
||
| if (preg_match('/(\/|\\\\)*(\.\.)+(\/|\\\\)*(.)*/', urldecode($filename)) !== 0) { |
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.
Please convince me why the regex /\.\.(\/|$)/ is not enough for our use case. Yours:
- Matches Windows-style backslashes which we can ignore because BIIGLE runs in Docker containers.
- Would also match something like
my-file..jpgormy..dir/file.jpgwhich should be fine. - Matches any trailing characters (
(.)*) which are irrelevant here.
| protected function pathIsValid($path) | ||
| { | ||
| if (preg_match('/(\/|\\\\)*(\.\.)+(\/|\\\\)*(.)*/', urldecode($path)) !== 0) { | ||
| return false; | ||
| } | ||
| return true; | ||
| } |
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.
Maybe set this as public static function so it can be reused in the VolumFiles rule?
| * Determine if the given path is valid | ||
| * | ||
| * @param string $path | ||
| * | ||
| * @return boolean | ||
| */ | ||
| protected function pathIsValid($path) |
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.
A more descriptive name could be pathHasDirectoryTraversal.
| } | ||
|
|
||
| if (preg_match('/(\/|\\\\)*(\.\.)+(\/|\\\\)*(.)*/', urldecode($filename)) !== 0) { | ||
| $this->message = 'Traversing directories is not allowed. Insert a valid path within the volume.'; |
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.
| $this->message = 'Traversing directories is not allowed. Insert a valid path within the volume.'; | |
| $this->message = 'Filenames with path traversal instructions are not allowed..'; |
| } | ||
|
|
||
| if (!$this->pathIsValid($value)) { | ||
| $this->message = 'The URL inserted is not valid. Please do not use path traversals.'; |
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.
| $this->message = 'The URL inserted is not valid. Please do not use path traversals.'; | |
| $this->message = 'Volume URLs with path traversal instructions are not allowed.'; |
| $path = $url[1]; | ||
|
|
||
| if (!$this->pathIsValid($path)) { | ||
| $this->message = "The path inserted is not valid. Please do not use path traversals"; |
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.
| $this->message = "The path inserted is not valid. Please do not use path traversals"; | |
| $this->message = "Volume URLs with path traversal instructions are not allowed."; |
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.
Instead of adding this twice, you could also prepend it once in passes().
Resolves #1110