Skip to content

Commit d86f980

Browse files
committed
Url could contain Javascript that leeds to XSS #1159
1 parent 5720147 commit d86f980

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

adm_program/system/classes/StringUtils.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ public static function strValidCharacters($string, $checkType)
182182
$validRegex = '=^[^/?*;:~<>|\"\\\\]+$=';
183183
break;
184184
case 'url':
185-
//$validRegex = '/^[\wáàâåäæçéèêîñóòôöõøœúùûüß$&!?() \/%=#:~.@+-]+$/i';
186-
$validRegex = '/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i';
185+
$validRegex = '/^[\wáàâåäæçéèêîñóòôöõøœúùûüß$&!?() \/%=#:~.@+-]+$/i';
186+
$validRegexValidUrl = '/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i';
187187
break;
188188
case 'phone':
189189
$validRegex = '/^[\d() \/+-]+$/i';
@@ -203,6 +203,11 @@ public static function strValidCharacters($string, $checkType)
203203
case 'email':
204204
return filter_var(trim($string), FILTER_VALIDATE_EMAIL) !== false;
205205
case 'url':
206+
// url has a valid structure
207+
if (!preg_match($validRegexValidUrl, $string)) {
208+
return false;
209+
}
210+
206211
return filter_var(trim($string), FILTER_VALIDATE_URL) !== false;
207212
default:
208213
return true;

0 commit comments

Comments
 (0)