Skip to content

Commit

Permalink
Prevent path traversal in $modx->runProcessor
Browse files Browse the repository at this point in the history
Similar to the patch in #13173, however specifically for processors executed via $modx->runProcessor. It's a lot harder to execute a successful path traversal through $modx->runProcessor as it's typically only used server-side without accepting user input. But, here you go.
  • Loading branch information
Mark-H committed Nov 14, 2016
1 parent befef7e commit 6040f64
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions core/model/modx/modx.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1659,12 +1659,18 @@ public function runProcessor($action = '',$scriptProperties = array(),$options =
$isClass = true;
$processorsPath = isset($options['processors_path']) && !empty($options['processors_path']) ? $options['processors_path'] : $this->config['processors_path'];
if (isset($options['location']) && !empty($options['location'])) $processorsPath .= ltrim($options['location'],'/') . '/';
$processorFile = $processorsPath.ltrim(str_replace('../', '', $action . '.class.php'),'/');

// Prevent path traversal through the action
$action = preg_replace('/(\.+\/)+/', '', htmlspecialchars($action));

// Find the processor file, preferring class based processors over old-style processors
$processorFile = $processorsPath.ltrim($action . '.class.php','/');
if (!file_exists($processorFile)) {
$processorFile = $processorsPath.ltrim(str_replace('../', '', $action . '.php'),'/');
$processorFile = $processorsPath.ltrim($action . '.php','/');
$isClass = false;
}

// Prepare a response
$response = '';
if (file_exists($processorFile)) {
if (!isset($this->lexicon)) $this->getService('lexicon', 'modLexicon');
Expand Down Expand Up @@ -1891,7 +1897,7 @@ public function logManagerAction($action, $class_key, $item, $userId = null) {
$userId = $this->user->get('id');
}
}

$ml = $this->newObject('modManagerLog');
$ml->set('user', (integer) $userId);
$ml->set('occurred', strftime('%Y-%m-%d %H:%M:%S'));
Expand Down

0 comments on commit 6040f64

Please sign in to comment.