Skip to content

Commit 470f534

Browse files
committed
Cross-site Scripting (XSS) when redirect an url
1 parent 96faecb commit 470f534

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

adm_program/system/bootstrap/function.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ function admFuncProcessableImageSize()
301301
* @param array<string,mixed> $array The array with the element that should be checked
302302
* @param string $variableName Name of the array element that should be checked
303303
* @param string $datatype The datatype like **string**, **numeric**, **int**, **float**, **bool**, **boolean**, **html**,
304-
* **date**, **file** or **folder** that is expected and which will be checked.
304+
* **url**, **date**, **file** or **folder** that is expected and which will be checked.
305305
* Datatype **date** expects a date that has the Admidio default format from the
306306
* preferences or the english date format **Y-m-d**
307307
* @param array<string,mixed> $options (optional) An array with the following possible entries:
@@ -387,7 +387,8 @@ function admFuncVariableIsValid(array $array, $variableName, $datatype, array $o
387387

388388
switch ($datatype)
389389
{
390-
case 'file':
390+
case 'file': // fallthrough
391+
case 'folder':
391392
try
392393
{
393394
if ($value !== '')
@@ -461,6 +462,12 @@ function admFuncVariableIsValid(array $array, $variableName, $datatype, array $o
461462
// check html string vor invalid tags and scripts
462463
$value = Htmlawed::filter(stripslashes($value), array('safe' => 1));
463464
break;
465+
466+
case 'url':
467+
if (!StringUtils::strValidCharacters($value, 'url')) {
468+
$errorMessage = $gL10n->get('SYS_INVALID_PAGE_VIEW');
469+
}
470+
break;
464471
}
465472

466473
// wurde kein Fehler entdeckt, dann den Inhalt der Variablen zurueckgeben

adm_program/system/classes/StringUtils.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ public static function strValidCharacters($string, $checkType)
182182
$validRegex = '=^[^/?*;:~<>|\"\\\\]+$=';
183183
break;
184184
case 'url':
185-
$validRegex = '/^[\wáàâåäæçéèêîñóòôöõøœúùûüß$&!?() \/%=#:~.@+-]+$/i';
185+
//$validRegex = '/^[\wáàâåäæçéèêîñóòôöõøœúùûüß$&!?() \/%=#:~.@+-]+$/i';
186+
$validRegex = '/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i';
186187
break;
187188
case 'phone':
188189
$validRegex = '/^[\d() \/+-]+$/i';

adm_program/system/redirect.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
require_once(__DIR__ . '/common.php');
2020

2121
// Initialize and check the parameters
22-
$getUrl = admFuncVariableIsValid($_GET, 'url', 'string', array('requireValue' => true));
22+
$getUrl = admFuncVariableIsValid($_GET, 'url', 'url', array('requireValue' => true));
2323

2424
if (filter_var($getUrl, FILTER_VALIDATE_URL) === false)
2525
{

0 commit comments

Comments
 (0)