68 $newstringnumentity = preg_replace(
'/;$/',
'', $matches[1]);
71 if (preg_match(
'/^x/i', $newstringnumentity)) {
72 $newstringnumentity = hexdec(preg_replace(
'/^x/i',
'', $newstringnumentity));
74 $newstringnumentity = (int) $newstringnumentity;
78 if (($newstringnumentity >= 47 && $newstringnumentity <= 59) || ($newstringnumentity >= 65 && $newstringnumentity <= 90) || ($newstringnumentity >= 97 && $newstringnumentity <= 122)) {
79 return chr((
int) $newstringnumentity);
84 foreach ($arrayofemojis as $valarray) {
85 if ($newstringnumentity >= hexdec($valarray[0]) && $newstringnumentity <= hexdec($valarray[1])) {
87 return html_entity_decode($matches[0], ENT_COMPAT | ENT_HTML5,
'UTF-8');
91 return '&#'.$matches[1];
115 $val = html_entity_decode($val, ENT_QUOTES | ENT_HTML5);
117 $val = preg_replace_callback(
118 '/&#(x?[0-9][0-9a-f]+;?)/i',
123 static function ($m) {
131 $val = preg_replace(
'/<!--[^>]*-->/',
'', $val);
132 $val = preg_replace(
'/[\r\n\t]/',
'', $val);
133 }
while ($oldval != $val);
144 $newval = preg_replace(
'/[\x00-\x08\x0B-\x0C\x0E-\x1F\x7F]/u',
'', $val);
147 if ($newval != $val) {
154 if ($type == 1 || $type == 3) {
156 $inj += preg_match(
'/delete[\/\*\s]*from/i', $val);
157 $inj += preg_match(
'/create[\/\*\s]*table/i', $val);
158 $inj += preg_match(
'/insert[\/\*\s]*into/i', $val);
159 $inj += preg_match(
'/select[\/\*\s]*from/i', $val);
160 $inj += preg_match(
'/from[\/\*\s]*dual/i', $val);
161 $inj += preg_match(
'/into[\/\*\s]*(outfile|dumpfile)/i', $val);
162 $inj += preg_match(
'/user[\/\*\s]*\(/i', $val);
163 $inj += preg_match(
'/information_schema/i', $val);
164 $inj += preg_match(
'/<svg/i', $val);
165 $inj += preg_match(
'/update[^&=\w].*set.+=/i', $val);
166 $inj += preg_match(
'/union.+select/i', $val);
170 $inj += preg_match(
'/select|update|delete|truncate|replace|group\s*by|concat|count|from|union/i', $val);
173 $inj += preg_match(
'/updatexml\(/i', $val);
174 $inj += preg_match(
'/(\.\.%2f)+/i', $val);
175 $inj += preg_match(
'/\s@@/', $val);
178 $inj += preg_match(
'/<\/textarea/i', $val);
184 $inj += preg_match(
'/<embed/i', $val);
185 if (!defined(
'NOSCANAUDIOFORINJECTION')) {
186 $inj += preg_match(
'/<audio/i', $val);
188 if (!defined(
'NOSCANIFRAMEFORINJECTION')) {
189 $inj += preg_match(
'/<iframe/i', $val);
191 if (!defined(
'NOSCANOBJECTFORINJECTION')) {
192 $inj += preg_match(
'/<object/i', $val);
194 $inj += preg_match(
'/<script/i', $val);
195 $inj += preg_match(
'/Set\.constructor/i', $val);
196 if (!defined(
'NOSTYLECHECK')) {
197 $inj += preg_match(
'/<style/i', $val);
199 $inj += preg_match(
'/base\s+href/si', $val);
200 $inj += preg_match(
'/=data:/si', $val);
203 $inj += preg_match(
'/on(abort|after|animation|auxclick|before|blur|bounce|cancel|canplay|canplaythrough|change|click|close|content|contextmenu|cuechange|copy|cut)[a-z]*\s*=/i', $val);
204 $inj += preg_match(
'/on(dblclick|drag|drop|durationchange|emptied|end|ended|error|focus|focusin|focusout|formdata|gotpointercapture|hashchange|input|invalid)[a-z]*\s*=/i', $val);
205 $inj += preg_match(
'/on(key|load|lostpointercapture|mouse)[a-z]*\s*=/i', $val);
206 $inj += preg_match(
'/on(offline|online|pagehide|pageshow|pointer)[a-z]*\s*=/i', $val);
207 $inj += preg_match(
'/on(paste|pause|play|playing|progress|ratechange|reset|resize|scroll|select|search|seeked|seeking|show|stalled|start|submit|suspend)[a-z]*\s*=/i', $val);
208 $inj += preg_match(
'/on(timeupdate|touch|transition|toggle|unload|volumechange|waiting|wheel)[a-z]*\s*=/i', $val);
210 $inj += preg_match(
'/on(repeat|begin|finish)[a-z]*\s*=/i', $val);
214 $tmpval = preg_replace(
'/<[^<]*>/',
'', $val);
217 $inj += preg_match(
'/on(mouse|drag|key|load|touch|pointer|select|transition)[a-z]*\s*=/i', $tmpval);
218 $inj += preg_match(
'/on(abort|after|animation|auxclick|before|blur|bounce|cancel|canplay|canplaythrough|change|click|close|contextmenu|cuechange|copy|cut)[a-z]*\s*=/i', $tmpval);
219 $inj += preg_match(
'/on(dblclick|drop|durationchange|emptied|end|ended|error|focus|focusin|focusout|formdata|gotpointercapture|hashchange|input|invalid)[a-z]*\s*=/i', $tmpval);
220 $inj += preg_match(
'/on(lostpointercapture|offline|online|pagehide|pageshow)[a-z]*\s*=/i', $tmpval);
221 $inj += preg_match(
'/on(paste|pause|play|playing|progress|ratechange|reset|resize|scroll|search|seeked|seeking|show|stalled|start|submit|suspend)[a-z]*\s*=/i', $tmpval);
222 $inj += preg_match(
'/on(timeupdate|toggle|unload|volumechange|waiting|wheel)[a-z]*\s*=/i', $tmpval);
224 $inj += preg_match(
'/on(repeat|begin|finish)[a-z]*\s*=/i', $tmpval);
227 $inj += preg_match(
'/:|:|:/i', $val);
228 $inj += preg_match(
'/j\s*a\s*v\s*a\s*s\s*c\s*r\s*i\s*p\s*t\s*:/i', $val);
229 $inj += preg_match(
'/vbscript\s*:/i', $val);
231 if ($type == 1 || $type == 3) {
232 $val = str_replace(
'enclosure="',
'enclosure=X', $val);
233 if (!defined(
"SECURITY_WAF_ALLOW_QUOTES_IN_GET") || !constant(
"SECURITY_WAF_ALLOW_QUOTES_IN_GET")) {
234 $inj += preg_match(
'/"/i', $val);
238 $inj += preg_match(
'/[:;"\'<>\?\(\){}\$%#]/', $val);
254 if (is_array($var)) {
255 foreach ($var as $key => $value) {
257 if ($type === 0 && defined(
'NOSCANPOSTFORINJECTION') && is_array(constant(
'NOSCANPOSTFORINJECTION')) && in_array($key, (array) constant(
'NOSCANPOSTFORINJECTION'))) {
265 http_response_code(403);
268 $ip = (empty($_SERVER[
'REMOTE_ADDR']) ?
'unknown' : $_SERVER[
'REMOTE_ADDR']);
271 $errormessage =
'Access refused to '.htmlentities($ip, ENT_COMPAT,
'UTF-8').
' by SQL or Script injection protection in main.inc.php:analyseVarsForSqlAndScriptsInjection type='.htmlentities((
string) $type, ENT_COMPAT,
'UTF-8');
274 $errormessage2 =
'page='.htmlentities((empty($_SERVER[
"REQUEST_URI"]) ?
'' : $_SERVER[
"REQUEST_URI"]), ENT_COMPAT,
'UTF-8');
275 $errormessage2 .=
' paramtype='.htmlentities((
string) $type, ENT_COMPAT,
'UTF-8');
276 $errormessage2 .=
' paramkey='.htmlentities($key, ENT_COMPAT,
'UTF-8');
277 $errormessage2 .=
' paramvalue='.htmlentities($value, ENT_COMPAT,
'UTF-8');
281 print
'Try to go back, fix data of your form and resubmit it. You can contact also your technical support.';
283 print
"\n".
'<!--'.
"\n";
284 print $errormessage2;
288 if (function_exists(
'error_log')) {
289 error_log($errormessage.
' '.substr($errormessage2, 2000));
296 if (class_exists(
'PHPUnit\Framework\TestSuite')) {
297 $message = $errormessage.
' '.substr($errormessage2, 2000);
298 throw new Exception(
"Security injection exception: $message");
313if (!empty($_SERVER[
"REQUEST_METHOD"]) && $_SERVER[
"REQUEST_METHOD"] ==
"TRACE") {
314 print
'Access refused with request method TRACE';
315 http_response_code(405);
320if (!defined(
'NOSCANPHPSELFFORINJECTION') && !empty($_SERVER[
"PHP_SELF"])) {
321 $morevaltochecklikepost = array($_SERVER[
"PHP_SELF"]);
325if (!defined(
'NOSCANGETFORINJECTION') && !empty($_SERVER[
"QUERY_STRING"])) {
329 $morevaltochecklikeget = array(urldecode($_SERVER[
"QUERY_STRING"]));
333if (!defined(
'NOSCANPOSTFORINJECTION') || is_array(constant(
'NOSCANPOSTFORINJECTION'))) {