| 1 |
<?php |
| 2 |
// phpcs:disable WordPress.Security.EscapeOutput.ExceptionNotEscaped |
| 3 |
if (!defined('ABSPATH') && !defined('MCDATAPATH')) exit; |
| 4 |
|
| 5 |
if (!trait_exists('WPRProtectFWRuleStringFunc_V676')) : |
| 6 |
trait WPRProtectFWRuleStringFunc_V676 { |
| 7 |
private function _rf_isNumeric() { |
| 8 |
$args = $this->processRuleFunctionParams( |
| 9 |
'isNumeric', |
| 10 |
func_num_args(), |
| 11 |
func_get_args(), |
| 12 |
1 |
| 13 |
); |
| 14 |
$value = $args[0]; |
| 15 |
|
| 16 |
return (WPRHelper::safePregMatch('/^\d+$/', $value)); |
| 17 |
} |
| 18 |
|
| 19 |
private function _rf_isRegularWord() { |
| 20 |
$args = $this->processRuleFunctionParams( |
| 21 |
'isRegularWord', |
| 22 |
func_num_args(), |
| 23 |
func_get_args(), |
| 24 |
1 |
| 25 |
); |
| 26 |
$value = $args[0]; |
| 27 |
|
| 28 |
return (WPRHelper::safePregMatch('/^\w+$/', $value)); |
| 29 |
} |
| 30 |
|
| 31 |
private function _rf_isSpecialWord() { |
| 32 |
$args = $this->processRuleFunctionParams( |
| 33 |
'isSpecialWord', |
| 34 |
func_num_args(), |
| 35 |
func_get_args(), |
| 36 |
1 |
| 37 |
); |
| 38 |
$value = $args[0]; |
| 39 |
|
| 40 |
return (WPRHelper::safePregMatch('/^\S+$/', $value)); |
| 41 |
} |
| 42 |
|
| 43 |
private function _rf_isRegularSentence() { |
| 44 |
$args = $this->processRuleFunctionParams( |
| 45 |
'isRegularSentence', |
| 46 |
func_num_args(), |
| 47 |
func_get_args(), |
| 48 |
1 |
| 49 |
); |
| 50 |
$value = $args[0]; |
| 51 |
|
| 52 |
return (WPRHelper::safePregMatch('/^[\w\s]+$/', $value)); |
| 53 |
} |
| 54 |
|
| 55 |
private function _rf_isSpecialCharsSentence() { |
| 56 |
$args = $this->processRuleFunctionParams( |
| 57 |
'isSpecialCharsSentence', |
| 58 |
func_num_args(), |
| 59 |
func_get_args(), |
| 60 |
1 |
| 61 |
); |
| 62 |
$value = $args[0]; |
| 63 |
|
| 64 |
return (WPRHelper::safePregMatch('/^[\w\W]+$/', $value)); |
| 65 |
} |
| 66 |
|
| 67 |
private function _rf_isLink() { |
| 68 |
$args = $this->processRuleFunctionParams( |
| 69 |
'isLink', |
| 70 |
func_num_args(), |
| 71 |
func_get_args(), |
| 72 |
1 |
| 73 |
); |
| 74 |
$value = $args[0]; |
| 75 |
|
| 76 |
return (WPRHelper::safePregMatch('/^(http|ftp)s?:\/\/\S+$/i', $value)); |
| 77 |
} |
| 78 |
|
| 79 |
private function _rf_isIpv4() { |
| 80 |
$args = $this->processRuleFunctionParams( |
| 81 |
'isIpv4', |
| 82 |
func_num_args(), |
| 83 |
func_get_args(), |
| 84 |
1 |
| 85 |
); |
| 86 |
$value = $args[0]; |
| 87 |
|
| 88 |
return (WPRHelper::safePregMatch('/^\b((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\b$/x', $value)); |
| 89 |
} |
| 90 |
|
| 91 |
private function _rf_isEmbededIpv4() { |
| 92 |
$args = $this->processRuleFunctionParams( |
| 93 |
'isEmbededIpv4', |
| 94 |
func_num_args(), |
| 95 |
func_get_args(), |
| 96 |
1 |
| 97 |
); |
| 98 |
$value = $args[0]; |
| 99 |
|
| 100 |
return (WPRHelper::safePregMatch('/\b((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\b/x', $value)); |
| 101 |
} |
| 102 |
|
| 103 |
private function _rf_isIpv6() { |
| 104 |
$args = $this->processRuleFunctionParams( |
| 105 |
'isIpv6', |
| 106 |
func_num_args(), |
| 107 |
func_get_args(), |
| 108 |
1 |
| 109 |
); |
| 110 |
$value = $args[0]; |
| 111 |
|
| 112 |
return (WPRHelper::safePregMatch('/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/x', $value)); |
| 113 |
} |
| 114 |
|
| 115 |
private function _rf_isEmbededIpv6() { |
| 116 |
$args = $this->processRuleFunctionParams( |
| 117 |
'isEmbededIpv6', |
| 118 |
func_num_args(), |
| 119 |
func_get_args(), |
| 120 |
1 |
| 121 |
); |
| 122 |
$value = $args[0]; |
| 123 |
|
| 124 |
return (WPRHelper::safePregMatch('/(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/x', $value)); |
| 125 |
} |
| 126 |
|
| 127 |
private function _rf_isEmail() { |
| 128 |
$args = $this->processRuleFunctionParams( |
| 129 |
'isEmail', |
| 130 |
func_num_args(), |
| 131 |
func_get_args(), |
| 132 |
1 |
| 133 |
); |
| 134 |
$value = $args[0]; |
| 135 |
|
| 136 |
return (WPRHelper::safePregMatch('/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/', $value)); |
| 137 |
} |
| 138 |
|
| 139 |
private function _rf_isEmbededEmail($value) { |
| 140 |
$args = $this->processRuleFunctionParams( |
| 141 |
'isEmbededEmail', |
| 142 |
func_num_args(), |
| 143 |
func_get_args(), |
| 144 |
1 |
| 145 |
); |
| 146 |
$value = $args[0]; |
| 147 |
|
| 148 |
return (WPRHelper::safePregMatch('/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}/', $value)); |
| 149 |
} |
| 150 |
|
| 151 |
private function _rf_isEmbededLink() { |
| 152 |
$args = $this->processRuleFunctionParams( |
| 153 |
'isEmbededLink', |
| 154 |
func_num_args(), |
| 155 |
func_get_args(), |
| 156 |
1 |
| 157 |
); |
| 158 |
$value = $args[0]; |
| 159 |
|
| 160 |
return (WPRHelper::safePregMatch('/(http|ftp)s?:\/\/\S+$/i', $value)); |
| 161 |
} |
| 162 |
|
| 163 |
private function _rf_isEmbededHtml() { |
| 164 |
$args = $this->processRuleFunctionParams( |
| 165 |
'isEmbededHtml', |
| 166 |
func_num_args(), |
| 167 |
func_get_args(), |
| 168 |
1 |
| 169 |
); |
| 170 |
$value = $args[0]; |
| 171 |
|
| 172 |
return (WPRHelper::safePregMatch('/<(html|head|title|base|link|meta|style|picture|source|img|iframe|embed|object|param|video|audio|track|map|area|form|label|input|button|select|datalist|optgroup|option|textarea|output|progress|meter|fieldset|legend|script|noscript|template|slot|canvas)/ix', $value)); |
| 173 |
} |
| 174 |
|
| 175 |
private function _rf_isFile() { |
| 176 |
$args = $this->processRuleFunctionParams( |
| 177 |
'isFile', |
| 178 |
func_num_args(), |
| 179 |
func_get_args(), |
| 180 |
1 |
| 181 |
); |
| 182 |
$value = $args[0]; |
| 183 |
|
| 184 |
return (WPRHelper::safePregMatch('/\.(jpg|jpeg|png|gif|ico|pdf|doc|docx|ppt|pptx|pps|ppsx|odt|xls|zip|gzip|xlsx|psd|mp3|m4a|ogg|wav|mp4|m4v|mov|wmv|avi|mpg|ogv|3gp|3g2|php|html|phtml|js|css)/ix', $value)); |
| 185 |
} |
| 186 |
|
| 187 |
private function _rf_isPathTraversal() { |
| 188 |
$args = $this->processRuleFunctionParams( |
| 189 |
'isPathTraversal', |
| 190 |
func_num_args(), |
| 191 |
func_get_args(), |
| 192 |
1 |
| 193 |
); |
| 194 |
$value = $args[0]; |
| 195 |
|
| 196 |
return (WPRHelper::safePregMatch('/(?:\.{2}[\/]+)/', $value)); |
| 197 |
} |
| 198 |
|
| 199 |
private function _rf_isPhpEval() { |
| 200 |
$args = $this->processRuleFunctionParams( |
| 201 |
'isPhpEval', |
| 202 |
func_num_args(), |
| 203 |
func_get_args(), |
| 204 |
1 |
| 205 |
); |
| 206 |
$value = $args[0]; |
| 207 |
|
| 208 |
return (WPRHelper::safePregMatch('/\\b(?i:eval)\\s*\\(\\s*(?i:base64_decode|exec|file_get_contents|gzinflate|passthru|shell_exec|stripslashes|system)\\s*\\(/', $value)); |
| 209 |
} |
| 210 |
|
| 211 |
private function _rf_isSubstring() { |
| 212 |
$args = $this->processRuleFunctionParams( |
| 213 |
'isSubstring', |
| 214 |
func_num_args(), |
| 215 |
func_get_args(), |
| 216 |
2 |
| 217 |
); |
| 218 |
$string = $args[0]; |
| 219 |
$substring = $args[1]; |
| 220 |
|
| 221 |
return strpos((string) $string, (string) $substring) !== false; |
| 222 |
} |
| 223 |
|
| 224 |
private function _rf_containsAnySubstring() { |
| 225 |
$args = $this->processRuleFunctionParams( |
| 226 |
'containsAnySubstring', |
| 227 |
func_num_args(), |
| 228 |
func_get_args(), |
| 229 |
2 |
| 230 |
); |
| 231 |
$string = $args[0]; |
| 232 |
$array_of_substrings = $args[1]; |
| 233 |
|
| 234 |
if (is_array($array_of_substrings)) { |
| 235 |
foreach ($array_of_substrings as $i => $substring) { |
| 236 |
if ($this->_rf_isSubstring($string, $substring)) { |
| 237 |
return true; |
| 238 |
} |
| 239 |
} |
| 240 |
} else { |
| 241 |
throw new WPRProtectRuleError_V676( |
| 242 |
$this->addExState("containsAnySubstring: Expects an array of substrings.") |
| 243 |
); |
| 244 |
} |
| 245 |
|
| 246 |
return false; |
| 247 |
} |
| 248 |
|
| 249 |
private function _rf_concatString() { |
| 250 |
$args = $this->processRuleFunctionParams( |
| 251 |
'concatString', |
| 252 |
func_num_args(), |
| 253 |
func_get_args(), |
| 254 |
2, |
| 255 |
['string', 'string'] |
| 256 |
); |
| 257 |
$source_str = $args[0]; |
| 258 |
$str = $args[1]; |
| 259 |
|
| 260 |
return $source_str . $str; |
| 261 |
} |
| 262 |
|
| 263 |
private function _rf_strPos() { |
| 264 |
$args = $this->processRuleFunctionParams( |
| 265 |
'strPos', |
| 266 |
func_num_args(), |
| 267 |
func_get_args(), |
| 268 |
2, |
| 269 |
['string', 'string'] |
| 270 |
); |
| 271 |
$haystack = $args[0]; |
| 272 |
$needle = $args[1]; |
| 273 |
$offset = isset($args[2]) ? $args[2] : 0; |
| 274 |
|
| 275 |
if (!is_int($offset)) { |
| 276 |
throw new WPRProtectRuleError_V676( |
| 277 |
$this->addExState("strPos: Offset should be an integer") |
| 278 |
); |
| 279 |
} |
| 280 |
|
| 281 |
return strpos($haystack, $needle, $offset); |
| 282 |
} |
| 283 |
|
| 284 |
private function _rf_checkStringsForSubstringsPos() { |
| 285 |
$args = $this->processRuleFunctionParams( |
| 286 |
'checkStringsForSubstringsPos', |
| 287 |
func_num_args(), |
| 288 |
func_get_args(), |
| 289 |
3, |
| 290 |
['array', 'array', 'integer'] |
| 291 |
); |
| 292 |
$strings = $args[0]; |
| 293 |
$sub_strings = $args[1]; |
| 294 |
$pos = $args[2]; |
| 295 |
|
| 296 |
foreach ($strings as $string) { |
| 297 |
foreach ($sub_strings as $sub_string) { |
| 298 |
$position = $this->_rf_strPos($string, $sub_string); |
| 299 |
if ($position === $pos) { |
| 300 |
return true; |
| 301 |
} |
| 302 |
} |
| 303 |
} |
| 304 |
|
| 305 |
return false; |
| 306 |
} |
| 307 |
|
| 308 |
private function _rf_splitString() { |
| 309 |
$args = $this->processRuleFunctionParams( |
| 310 |
'splitString', |
| 311 |
func_num_args(), |
| 312 |
func_get_args(), |
| 313 |
2, |
| 314 |
['string', 'string'] |
| 315 |
); |
| 316 |
$separator = $args[0]; |
| 317 |
$str = $args[1]; |
| 318 |
$limit = isset($args[2]) ? $args[2] : PHP_INT_MAX; |
| 319 |
|
| 320 |
if (empty($separator)) { |
| 321 |
throw new WPRProtectRuleError_V676( |
| 322 |
$this->addExState("splitString: Separator cannot be empty") |
| 323 |
); |
| 324 |
} |
| 325 |
|
| 326 |
if (!is_int($limit)) { |
| 327 |
throw new WPRProtectRuleError_V676( |
| 328 |
$this->addExState("splitString: Limit should be an integer") |
| 329 |
); |
| 330 |
} |
| 331 |
|
| 332 |
return explode($separator, $str, $limit); |
| 333 |
} |
| 334 |
|
| 335 |
private function _rf_urlDecode() { |
| 336 |
$args = $this->processRuleFunctionParams( |
| 337 |
'urlDecode', |
| 338 |
func_num_args(), |
| 339 |
func_get_args(), |
| 340 |
1 |
| 341 |
); |
| 342 |
$value = $args[0]; |
| 343 |
$recursive = isset($args[1]) ? $args[1] : true; |
| 344 |
|
| 345 |
if (!is_bool($recursive)) { |
| 346 |
throw new WPRProtectRuleError_V676( |
| 347 |
$this->addExState("urlDecode: Recursive flag should be a boolean") |
| 348 |
); |
| 349 |
} |
| 350 |
|
| 351 |
return $this->normalizeStringValue($value, 'urlDecode', $recursive); |
| 352 |
} |
| 353 |
|
| 354 |
private function _rf_rawUrlDecode() { |
| 355 |
$args = $this->processRuleFunctionParams( |
| 356 |
'rawUrlDecode', |
| 357 |
func_num_args(), |
| 358 |
func_get_args(), |
| 359 |
1 |
| 360 |
); |
| 361 |
$value = $args[0]; |
| 362 |
$recursive = isset($args[1]) ? $args[1] : true; |
| 363 |
|
| 364 |
if (!is_bool($recursive)) { |
| 365 |
throw new WPRProtectRuleError_V676( |
| 366 |
$this->addExState("rawUrlDecode: Recursive flag should be a boolean") |
| 367 |
); |
| 368 |
} |
| 369 |
|
| 370 |
return $this->normalizeStringValue($value, 'rawUrlDecode', $recursive); |
| 371 |
} |
| 372 |
|
| 373 |
private function _rf_htmlEntityDecode() { |
| 374 |
$args = $this->processRuleFunctionParams( |
| 375 |
'htmlEntityDecode', |
| 376 |
func_num_args(), |
| 377 |
func_get_args(), |
| 378 |
1 |
| 379 |
); |
| 380 |
$value = $args[0]; |
| 381 |
$recursive = isset($args[1]) ? $args[1] : true; |
| 382 |
|
| 383 |
if (!is_bool($recursive)) { |
| 384 |
throw new WPRProtectRuleError_V676( |
| 385 |
$this->addExState("htmlEntityDecode: Recursive flag should be a boolean") |
| 386 |
); |
| 387 |
} |
| 388 |
|
| 389 |
return $this->normalizeStringValue($value, 'htmlEntityDecode', $recursive); |
| 390 |
} |
| 391 |
|
| 392 |
private function _rf_stripSlashes() { |
| 393 |
$args = $this->processRuleFunctionParams( |
| 394 |
'stripSlashes', |
| 395 |
func_num_args(), |
| 396 |
func_get_args(), |
| 397 |
1 |
| 398 |
); |
| 399 |
$value = $args[0]; |
| 400 |
$recursive = isset($args[1]) ? $args[1] : true; |
| 401 |
|
| 402 |
if (!is_bool($recursive)) { |
| 403 |
throw new WPRProtectRuleError_V676( |
| 404 |
$this->addExState("stripSlashes: Recursive flag should be a boolean") |
| 405 |
); |
| 406 |
} |
| 407 |
|
| 408 |
return $this->normalizeStringValue($value, 'stripSlashes', $recursive); |
| 409 |
} |
| 410 |
|
| 411 |
private function normalizeStringValue($value, $operation, $recursive, $depth = 1) { |
| 412 |
if ($depth > WPRProtectFWRuleEngine_V676::MAX_DEPTH_TO_ALLOWED_TYPE_FUNC) { |
| 413 |
return null; |
| 414 |
} |
| 415 |
|
| 416 |
if (is_array($value)) { |
| 417 |
if (!$recursive) { |
| 418 |
return $value; |
| 419 |
} |
| 420 |
|
| 421 |
$normalized = array(); |
| 422 |
foreach ($value as $key => $item) { |
| 423 |
$normalized[$key] = $this->normalizeStringValue($item, $operation, $recursive, $depth + 1); |
| 424 |
} |
| 425 |
|
| 426 |
return $normalized; |
| 427 |
} |
| 428 |
|
| 429 |
if (!is_string($value)) { |
| 430 |
return $value; |
| 431 |
} |
| 432 |
|
| 433 |
switch ($operation) { |
| 434 |
case 'urlDecode': |
| 435 |
return urldecode($value); |
| 436 |
case 'rawUrlDecode': |
| 437 |
return rawurldecode($value); |
| 438 |
case 'htmlEntityDecode': |
| 439 |
return html_entity_decode($value, ENT_QUOTES | ENT_HTML5, 'UTF-8'); |
| 440 |
case 'stripSlashes': |
| 441 |
return stripslashes($value); |
| 442 |
} |
| 443 |
|
| 444 |
throw new WPRProtectRuleError_V676( |
| 445 |
$this->addExState("normalizeStringValue: Invalid normalization operation") |
| 446 |
); |
| 447 |
} |
| 448 |
} |
| 449 |
endif; |
| 450 |
|