Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

Commit e6afe73

Browse files
committed
Add new DIRNAME mode for sanitization, same as filenames except that it lets the / pass through.
Use strpos() instead of deprecated ereg() function.
1 parent 3a871bc commit e6afe73

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

core/src/core/classes/class.AJXP_Utils.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
define('AJXP_SANITIZE_ALPHANUM', 3);
2626
define('AJXP_SANITIZE_EMAILCHARS', 4);
2727
define('AJXP_SANITIZE_FILENAME', 5);
28+
define('AJXP_SANITIZE_DIRNAME', 6);
2829

2930
// THESE ARE DEFINED IN bootstrap_context.php
3031
// REPEAT HERE FOR BACKWARD COMPATIBILITY.
@@ -189,7 +190,7 @@ public static function sanitize($s, $level = AJXP_SANITIZE_HTML, $expand = 'scri
189190
return preg_replace("/[^a-zA-Z0-9_\-\.]/", "", $s);
190191
} else if ($level == AJXP_SANITIZE_EMAILCHARS) {
191192
return preg_replace("/[^a-zA-Z0-9_\-\.@!%\+=|~\?]/", "", $s);
192-
} else if ($level == AJXP_SANITIZE_FILENAME) {
193+
} else if ($level == AJXP_SANITIZE_FILENAME || $level == AJXP_SANITIZE_DIRNAME) {
193194
// Convert Hexadecimals
194195
$s = preg_replace_callback('!(&#|\\\)[xX]([0-9a-fA-F]+);?!', array('AJXP_Utils', 'clearHexaCallback'), $s);
195196
// Clean up entities
@@ -199,9 +200,11 @@ public static function sanitize($s, $level = AJXP_SANITIZE_HTML, $expand = 'scri
199200
// Strip whitespace characters
200201
$s = trim($s);
201202
$s = str_replace(chr(0), "", $s);
202-
$s = preg_replace("/[\"\/\|\?\\\]/", "", $s);
203+
if($level == AJXP_SANITIZE_FILENAME) $s = preg_replace("/[\"\/\|\?\\\]/", "", $s);
204+
else $s = preg_replace("/[\"\|\?\\\]/", "", $s);
203205
if(self::detectXSS($s)){
204-
$s = "XSS Detected - Rename Me";
206+
if(strpos($s, "/") === 0) $s = "/XSS Detected - Rename Me";
207+
else $s = "XSS Detected - Rename Me";
205208
}
206209
return $s;
207210
}
@@ -337,7 +340,7 @@ public static function parseFileDataErrors($boxData, $throwException=false)
337340
$errorsArray[UPLOAD_ERR_EXTENSION] = array(410, $mess[542]);
338341
if ($userfile_error == UPLOAD_ERR_NO_FILE) {
339342
// OPERA HACK, do not display "no file found error"
340-
if (!ereg('Opera', $_SERVER['HTTP_USER_AGENT'])) {
343+
if (strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') === false) {
341344
$data = $errorsArray[$userfile_error];
342345
if($throwException) throw new Exception($data[1], $data[0]);
343346
return $data;

core/src/plugins/access.fs/class.fsAccessDriver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public function switchAction($action, $httpVars, $fileVars)
233233
if(!isSet($this->actions[$action])) return;
234234
parent::accessPreprocess($action, $httpVars, $fileVars);
235235
$selection = new UserSelection($this->repository);
236-
$dir = $httpVars["dir"] OR "";
236+
$dir = AJXP_Utils::sanitize($httpVars["dir"], AJXP_SANITIZE_DIRNAME) OR "";
237237
if ($this->wrapperClassName == "fsAccessWrapper") {
238238
$dir = fsAccessWrapper::patchPathForBaseDir($dir);
239239
}

0 commit comments

Comments
 (0)