Skip to content

Conversation

@dbrembilla
Copy link
Contributor

Resolves #1110

@dbrembilla dbrembilla marked this pull request as draft December 16, 2025 08:16
@dbrembilla dbrembilla marked this pull request as ready for review December 16, 2025 09:43
@dbrembilla dbrembilla requested a review from mzur December 16, 2025 09:43
@dbrembilla dbrembilla self-assigned this Jan 2, 2026
return false;
}

if (preg_match('/(\/|\\\\)*(\.\.)+(\/|\\\\)*(.)*/', urldecode($filename)) !== 0) {
Copy link
Member

@mzur mzur Jan 5, 2026

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..jpg or my..dir/file.jpg which should be fine.
  • Matches any trailing characters ((.)*) which are irrelevant here.

Comment on lines +197 to +203
protected function pathIsValid($path)
{
if (preg_match('/(\/|\\\\)*(\.\.)+(\/|\\\\)*(.)*/', urldecode($path)) !== 0) {
return false;
}
return true;
}
Copy link
Member

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?

Comment on lines +191 to +197
* Determine if the given path is valid
*
* @param string $path
*
* @return boolean
*/
protected function pathIsValid($path)
Copy link
Member

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.';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$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.';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$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";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$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.";

Copy link
Member

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().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Strip directory traversal instructions from volume and file paths

3 participants