Skip to content
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

Change sanitize behavior for files with two dots in filename #14330

Open
wants to merge 5 commits into
base: 2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/model/modx/processors/browser/file/create.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function process() {
$directory = ltrim(strip_tags(preg_replace('/[\.]{2,}/', '', htmlspecialchars($directory))),'/');

$name = $this->getProperty('name');
$name = ltrim(strip_tags(preg_replace('/[\.]{2,}/', '', htmlspecialchars($name))),'/');
$name = ltrim(strip_tags(htmlspecialchars($name)),'/');

$loaded = $this->getSource();
if (!($this->source instanceof modMediaSource)) {
Expand Down
10 changes: 8 additions & 2 deletions core/model/modx/processors/browser/file/remove.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ public function process() {
if (empty($file)) {
return $this->modx->error->failure($this->modx->lexicon('file_err_ns'));
}
$file = preg_replace('/[\.]{2,}/', '', $file);
$pathinfo = pathinfo($file);
if ($pathinfo['dirname'].DIRECTORY_SEPARATOR.$pathinfo['basename'] != $file) {
$this->modx->log (modX::LOG_LEVEL_ERROR, 'Could not prepare the filepath ' . $file . '. Please set a valid UTF8 capable locale in the MODX system setting "locale".');
}
$directory = preg_replace('/[\.]{2,}/', '', htmlspecialchars($pathinfo['dirname']));
$name = htmlspecialchars($pathinfo['basename']);
$path = $directory.DIRECTORY_SEPARATOR.$name;

$loaded = $this->getSource();
if (!($this->source instanceof modMediaSource)) {
Expand All @@ -42,7 +48,7 @@ public function process() {
if (!$this->source->checkPolicy('remove')) {
return $this->failure($this->modx->lexicon('permission_denied'));
}
$success = $this->source->removeObject($file);
$success = $this->source->removeObject($path);

if (empty($success)) {
$errors = $this->source->getErrors();
Expand Down
21 changes: 17 additions & 4 deletions core/model/modx/processors/browser/file/rename.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,23 @@ public function process() {
}

$oldFile = $this->getProperty('path');
$oldFile = preg_replace('/[\.]{2,}/', '', htmlspecialchars($oldFile));
$name = $this->getProperty('name');
$name = preg_replace('/[\.]{2,}/', '', htmlspecialchars($name));
$success = $this->source->renameObject($oldFile, $name);
$pathinfo = pathinfo($oldFile);
if ($pathinfo['dirname'].DIRECTORY_SEPARATOR.$pathinfo['basename'] != $oldFile) {
$this->modx->log (modX::LOG_LEVEL_ERROR, 'Could not prepare the filepath ' . $oldFile . '. Please set a valid UTF8 capable locale in the MODX system setting "locale".');
}
$directory = preg_replace('/[\.]{2,}/', '', htmlspecialchars($pathinfo['dirname']));
$name = htmlspecialchars($pathinfo['basename']);
$oldFile = $directory.DIRECTORY_SEPARATOR.$name;

$newFile = $this->getProperty('name');
$pathinfo = pathinfo($newFile);
if ($pathinfo['basename'] != $newFile) {
$this->modx->log (modX::LOG_LEVEL_ERROR, 'Could not prepare the filepath ' . $newFile . '. Please set a valid UTF8 capable locale in the MODX system setting "locale".');
}
$directory = preg_replace('/[\.]{2,}/', '', htmlspecialchars($pathinfo['dirname']));
$name = htmlspecialchars($pathinfo['basename']);
$newFile = $directory.DIRECTORY_SEPARATOR.$name;
$success = $this->source->renameObject($oldFile, $newFile);

if (empty($success)) {
$msg = '';
Expand Down