| @@ -1,13 +1,13 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | if (!defined('ABSPATH') && !defined('MCDATAPATH')) exit; |
| 3 | 3 | |
| 4 | -if (!class_exists('WPRProtectFW_V556')) : | |
| 4 | +if (!class_exists('WPRProtectFW_V636')) : | |
| 5 | 5 | require_once dirname( __FILE__ ) . '/fw/rule/errors.php'; |
| 6 | 6 | require_once dirname( __FILE__ ) . '/fw/rule/engine.php'; |
| 7 | 7 | require_once dirname( __FILE__ ) . '/fw/rule.php'; |
| 8 | 8 | |
| 9 | -class WPRProtectFW_V556 { | |
| 9 | +class WPRProtectFW_V636 { | |
| 10 | 10 | private $brand_name; |
| 11 | 11 | private $protect_mode; |
| 12 | 12 | private $request; |
| 13 | 13 | private $ipstore; |
| @@ -21,24 +21,25 @@ | ||
| 21 | 21 | private $is_on_boot_rules_executed = false; |
| 22 | 22 | private $is_ip_checked_for_blacklisted = false; |
| 23 | 23 | private $has_valid_bypass_cookie; |
| 24 | 24 | |
| 25 | - private $mode = WPRProtectFW_V556::MODE_DISABLED; | |
| 26 | - private $ip_cookie_mode = WPRProtectFW_V556::IP_COOKIE_MODE_DISABLED; | |
| 27 | - private $admin_cookie_mode = WPRProtectFW_V556::ADMIN_COOKIE_MODE_DISABLED; | |
| 28 | - private $bypass_level = WPRProtectFW_V556::WP_USER_ROLE_LEVEL_CONTRIBUTOR; | |
| 29 | - private $wpf_rule_init_mode = WPRProtectFW_V556::WPF_RULE_INIT_MODE_WP; | |
| 25 | + private $mode = WPRProtectFW_V636::MODE_DISABLED; | |
| 26 | + private $ip_cookie_mode = WPRProtectFW_V636::IP_COOKIE_MODE_DISABLED; | |
| 27 | + private $admin_cookie_mode = WPRProtectFW_V636::ADMIN_COOKIE_MODE_DISABLED; | |
| 28 | + private $bypass_level = WPRProtectFW_V636::WP_USER_ROLE_LEVEL_CONTRIBUTOR; | |
| 29 | + private $wpf_rule_init_mode = WPRProtectFW_V636::WPF_RULE_INIT_MODE_WP; | |
| 30 | 30 | private $custom_roles = array(); |
| 31 | 31 | private $cookie_key = ""; |
| 32 | 32 | private $cookie_path = ""; |
| 33 | 33 | private $cookie_domain = ""; |
| 34 | + private $cookie_validity = 2592000; | |
| 34 | 35 | private $can_set_cache_prevention_cookie = false; |
| 35 | - private $rules_mode = WPRProtectFW_V556::RULES_MODE_DISABLED; | |
| 36 | + private $rules_mode = WPRProtectFW_V636::RULES_MODE_DISABLED; | |
| 36 | 37 | private $is_geo_blocking = false; |
| 37 | 38 | private $is_wp_user_cookie_enabled = false; |
| 38 | 39 | private $log_config = array(); |
| 39 | - private $request_profiling_mode = WPRProtectFW_V556::REQ_PROFILING_MODE_DISABLED; | |
| 40 | - private $logging_mode = WPRProtectFW_V556::LOGGING_MODE_VISITOR; | |
| 40 | + private $request_profiling_mode = WPRProtectFW_V636::REQ_PROFILING_MODE_DISABLED; | |
| 41 | + private $logging_mode = WPRProtectFW_V636::LOGGING_MODE_VISITOR; | |
| 41 | 42 | private $skip_log_config = array(); |
| 42 | 43 | private $skip_log_cookies = array(); |
| 43 | 44 | private $skip_log_headers = array(); |
| 44 | 45 | private $skip_log_post_params = array(); |
| @@ -51,9 +52,9 @@ | ||
| 51 | 52 | private $rule_log = array(); |
| 52 | 53 | private $matched_rules = array(); |
| 53 | 54 | private $break_rule_matching = false; |
| 54 | 55 | private $can_log_raw_body = false; |
| 55 | - private $log_slice_size = WPRProtectFW_V556::LOG_SLICE_SIZE; | |
| 56 | + private $log_slice_size = WPRProtectFW_V636::LOG_SLICE_SIZE; | |
| 56 | 57 | |
| 57 | 58 | private static $instance = null; |
| 58 | 59 | |
| 59 | 60 | const MODE_DISABLED = 1; |
| @@ -97,18 +98,18 @@ | ||
| 97 | 98 | const LOGGING_MODE_COMPLETE = 2; |
| 98 | 99 | const LOGGING_MODE_DISABLED = 3; |
| 99 | 100 | |
| 100 | 101 | const DEFAULT_WP_USER_ROLE_LEVELS = array( |
| 101 | - 'administrator' => WPRProtectFW_V556::WP_USER_ROLE_LEVEL_ADMIN, | |
| 102 | - 'editor' => WPRProtectFW_V556::WP_USER_ROLE_LEVEL_EDITOR, | |
| 103 | - 'author' => WPRProtectFW_V556::WP_USER_ROLE_LEVEL_AUTHOR, | |
| 104 | - 'contributor' => WPRProtectFW_V556::WP_USER_ROLE_LEVEL_CONTRIBUTOR, | |
| 105 | - 'subscriber' => WPRProtectFW_V556::WP_USER_ROLE_LEVEL_SUBSCRIBER | |
| 102 | + 'administrator' => WPRProtectFW_V636::WP_USER_ROLE_LEVEL_ADMIN, | |
| 103 | + 'editor' => WPRProtectFW_V636::WP_USER_ROLE_LEVEL_EDITOR, | |
| 104 | + 'author' => WPRProtectFW_V636::WP_USER_ROLE_LEVEL_AUTHOR, | |
| 105 | + 'contributor' => WPRProtectFW_V636::WP_USER_ROLE_LEVEL_CONTRIBUTOR, | |
| 106 | + 'subscriber' => WPRProtectFW_V636::WP_USER_ROLE_LEVEL_SUBSCRIBER | |
| 106 | 107 | ); |
| 107 | 108 | |
| 108 | 109 | const EXTRA_WP_USER_ROLE_LEVELS = array( |
| 109 | - 'custom' => WPRProtectFW_V556::WP_USER_ROLE_LEVEL_CUSTOM, | |
| 110 | - 'unknown' => WPRProtectFW_V556::WP_USER_ROLE_LEVEL_UNKNOWN | |
| 110 | + 'custom' => WPRProtectFW_V636::WP_USER_ROLE_LEVEL_CUSTOM, | |
| 111 | + 'unknown' => WPRProtectFW_V636::WP_USER_ROLE_LEVEL_UNKNOWN | |
| 111 | 112 | ); |
| 112 | 113 | |
| 113 | 114 | const TABLE_NAME = "fw_requests"; |
| 114 | 115 | const IP_COOKIE_NAME = "mcfw-ip-cookie"; |
| @@ -169,8 +170,12 @@ | ||
| 169 | 170 | if (array_key_exists('cookiedomain', $config) && is_string($config['cookiedomain'])) { |
| 170 | 171 | $this->cookie_domain = $config['cookiedomain']; |
| 171 | 172 | } |
| 172 | 173 | |
| 174 | + if (array_key_exists('cookievalidity', $config) && is_int($config['cookievalidity'])) { | |
| 175 | + $this->cookie_validity = $config['cookievalidity']; | |
| 176 | + } | |
| 177 | + | |
| 173 | 178 | if (array_key_exists('cansetcachepreventioncookie', $config) && |
| 174 | 179 | is_bool($config['cansetcachepreventioncookie'])) { |
| 175 | 180 | |
| 176 | 181 | $this->can_set_cache_prevention_cookie = $config['cansetcachepreventioncookie']; |
| @@ -241,13 +246,13 @@ | ||
| 241 | 246 | } |
| 242 | 247 | |
| 243 | 248 | if ($this->isPrependMode()) { |
| 244 | 249 | $log_file = MCDATAPATH . MCCONFKEY . '-mc.log'; |
| 245 | - $this->ipstore = new WPRProtectIpstore_V556(WPRProtectIpstore_V556::STORAGE_TYPE_FS); | |
| 246 | - $this->logger = new WPRProtectLogger_V556($log_file, WPRProtectLogger_V556::TYPE_FS); | |
| 250 | + $this->ipstore = new WPRProtectIpstore_V636(WPRProtectIpstore_V636::STORAGE_TYPE_FS); | |
| 251 | + $this->logger = new WPRProtectLogger_V636($log_file, WPRProtectLogger_V636::TYPE_FS); | |
| 247 | 252 | } else { |
| 248 | - $this->ipstore = new WPRProtectIpstore_V556(WPRProtectIpstore_V556::STORAGE_TYPE_DB); | |
| 249 | - $this->logger = new WPRProtectLogger_V556(WPRProtectFW_V556::TABLE_NAME, WPRProtectLogger_V556::TYPE_DB); | |
| 253 | + $this->ipstore = new WPRProtectIpstore_V636(WPRProtectIpstore_V636::STORAGE_TYPE_DB); | |
| 254 | + $this->logger = new WPRProtectLogger_V636(WPRProtectFW_V636::TABLE_NAME, WPRProtectLogger_V636::TYPE_DB); | |
| 250 | 255 | } |
| 251 | 256 | |
| 252 | 257 | if ($this->is_wp_user_cookie_enabled) { |
| 253 | 258 | $this->loadWPUser(); |
| @@ -258,12 +263,12 @@ | ||
| 258 | 263 | |
| 259 | 264 | public static function getInstance($protect_mode, $request, $config, $brand_name) { |
| 260 | 265 | if (!isset(self::$instance)) { |
| 261 | 266 | self::$instance = new self($protect_mode, $request, $config, $brand_name); |
| 262 | - } elseif (self::$instance->protect_mode != $protect_mode && $protect_mode == WPRProtect_V556::MODE_WP) { | |
| 267 | + } elseif (self::$instance->protect_mode != $protect_mode && $protect_mode == WPRProtect_V636::MODE_WP) { | |
| 263 | 268 | self::$instance->protect_mode = $protect_mode; |
| 264 | 269 | self::$instance->brand_name = $brand_name; |
| 265 | - self::$instance->ipstore = new WPRProtectIpstore_V556(WPRProtectIpstore_V556::STORAGE_TYPE_DB); | |
| 270 | + self::$instance->ipstore = new WPRProtectIpstore_V636(WPRProtectIpstore_V636::STORAGE_TYPE_DB); | |
| 266 | 271 | self::$instance->initRules(); |
| 267 | 272 | } |
| 268 | 273 | |
| 269 | 274 | return self::$instance; |
| @@ -269,9 +274,9 @@ | ||
| 269 | 274 | return self::$instance; |
| 270 | 275 | } |
| 271 | 276 | |
| 272 | 277 | public static function uninstall() { |
| 273 | - WPRProtect_V556::$db->dropBVTable(WPRProtectFW_V556::TABLE_NAME); | |
| 278 | + WPRProtect_V636::$db->dropBVTable(WPRProtectFW_V636::TABLE_NAME); | |
| 274 | 279 | } |
| 275 | 280 | |
| 276 | 281 | public function init() { |
| 277 | 282 | if (!$this->isModeDisabled()) { |
| @@ -289,42 +294,42 @@ | ||
| 289 | 294 | } |
| 290 | 295 | } |
| 291 | 296 | |
| 292 | 297 | private function isPrependMode() { |
| 293 | - return ($this->protect_mode === WPRProtect_V556::MODE_PREPEND); | |
| 298 | + return ($this->protect_mode === WPRProtect_V636::MODE_PREPEND); | |
| 294 | 299 | } |
| 295 | 300 | |
| 296 | 301 | private function isWPMode() { |
| 297 | - return ($this->protect_mode === WPRProtect_V556::MODE_WP); | |
| 302 | + return ($this->protect_mode === WPRProtect_V636::MODE_WP); | |
| 298 | 303 | } |
| 299 | 304 | |
| 300 | 305 | private function isModeDisabled() { |
| 301 | - return ($this->mode === WPRProtectFW_V556::MODE_DISABLED); | |
| 306 | + return ($this->mode === WPRProtectFW_V636::MODE_DISABLED); | |
| 302 | 307 | } |
| 303 | 308 | |
| 304 | 309 | private function isModeProtect() { |
| 305 | - return ($this->mode === WPRProtectFW_V556::MODE_PROTECT); | |
| 310 | + return ($this->mode === WPRProtectFW_V636::MODE_PROTECT); | |
| 306 | 311 | } |
| 307 | 312 | |
| 308 | 313 | private function isAdminCookieEnabled() { |
| 309 | - return ($this->admin_cookie_mode === WPRProtectFW_V556::ADMIN_COOKIE_MODE_ENABLED); | |
| 314 | + return ($this->admin_cookie_mode === WPRProtectFW_V636::ADMIN_COOKIE_MODE_ENABLED); | |
| 310 | 315 | } |
| 311 | 316 | |
| 312 | 317 | private function isIPCookieEnabled() { |
| 313 | - return ($this->ip_cookie_mode === WPRProtectFW_V556::IP_COOKIE_MODE_ENABLED); | |
| 318 | + return ($this->ip_cookie_mode === WPRProtectFW_V636::IP_COOKIE_MODE_ENABLED); | |
| 314 | 319 | } |
| 315 | 320 | |
| 316 | 321 | private function isRequestProfilingDisabled() { |
| 317 | - return ($this->request_profiling_mode === WPRProtectFW_V556::REQ_PROFILING_MODE_DISABLED); | |
| 322 | + return ($this->request_profiling_mode === WPRProtectFW_V636::REQ_PROFILING_MODE_DISABLED); | |
| 318 | 323 | } |
| 319 | 324 | |
| 320 | 325 | private function isRequestProfilingModeDebug() { |
| 321 | - return ($this->request_profiling_mode === WPRProtectFW_V556::REQ_PROFILING_MODE_DEBUG); | |
| 326 | + return ($this->request_profiling_mode === WPRProtectFW_V636::REQ_PROFILING_MODE_DEBUG); | |
| 322 | 327 | } |
| 323 | 328 | |
| 324 | 329 | private function isRequestHasValidBypassCookie() { |
| 325 | 330 | if (!isset($this->has_valid_bypass_cookie)) { |
| 326 | - $cookie = (string) $this->request->getCookies(WPRProtectFW_V556::BYPASS_COOKIE_NAME); | |
| 331 | + $cookie = (string) $this->request->getCookies(WPRProtectFW_V636::BYPASS_COOKIE_NAME); | |
| 327 | 332 | $new_cookie = $this->generateBypassCookie(); |
| 328 | 333 | $is_valid = ($this->isAdminCookieEnabled() && $new_cookie && ($cookie === $new_cookie)); |
| 329 | 334 | $this->has_valid_bypass_cookie = $is_valid; |
| 330 | 335 | } |
| @@ -332,17 +337,17 @@ | ||
| 332 | 337 | return $this->has_valid_bypass_cookie; |
| 333 | 338 | } |
| 334 | 339 | |
| 335 | 340 | private function isRulesModeProtect() { |
| 336 | - return ($this->rules_mode === WPRProtectFW_V556::RULES_MODE_PROTECT); | |
| 341 | + return ($this->rules_mode === WPRProtectFW_V636::RULES_MODE_PROTECT); | |
| 337 | 342 | } |
| 338 | 343 | |
| 339 | 344 | public function isLoggingModeComplete() { |
| 340 | - return ($this->logging_mode === WPRProtectFW_V556::LOGGING_MODE_COMPLETE); | |
| 345 | + return ($this->logging_mode === WPRProtectFW_V636::LOGGING_MODE_COMPLETE); | |
| 341 | 346 | } |
| 342 | 347 | |
| 343 | 348 | public function isLoggingModeVisitor() { |
| 344 | - return ($this->logging_mode === WPRProtectFW_V556::LOGGING_MODE_VISITOR); | |
| 349 | + return ($this->logging_mode === WPRProtectFW_V636::LOGGING_MODE_VISITOR); | |
| 345 | 350 | } |
| 346 | 351 | |
| 347 | 352 | public function isGeoBlockingEnabled() { |
| 348 | 353 | return ($this->is_geo_blocking === true); |
| @@ -348,13 +353,13 @@ | ||
| 348 | 353 | return ($this->is_geo_blocking === true); |
| 349 | 354 | } |
| 350 | 355 | |
| 351 | 356 | private function isWPFRuleInitModePrepend() { |
| 352 | - return ($this->wpf_rule_init_mode === WPRProtectFW_V556::WPF_RULE_INIT_MODE_PREPEND); | |
| 357 | + return ($this->wpf_rule_init_mode === WPRProtectFW_V636::WPF_RULE_INIT_MODE_PREPEND); | |
| 353 | 358 | } |
| 354 | 359 | |
| 355 | 360 | private function isWPFRuleInitModeWP() { |
| 356 | - return ($this->wpf_rule_init_mode === WPRProtectFW_V556::WPF_RULE_INIT_MODE_WP); | |
| 361 | + return ($this->wpf_rule_init_mode === WPRProtectFW_V636::WPF_RULE_INIT_MODE_WP); | |
| 357 | 362 | } |
| 358 | 363 | |
| 359 | 364 | private function canInitWPFRules() { |
| 360 | 365 | if (!$this->isWPFRuleInitModePrepend() && $this->isPrependMode()) { |
| @@ -364,9 +369,9 @@ | ||
| 364 | 369 | return true; |
| 365 | 370 | } |
| 366 | 371 | |
| 367 | 372 | private function generateBypassCookie() { |
| 368 | - $time = floor(time() / 43200); | |
| 373 | + $time = floor(time() / $this->cookie_validity); | |
| 369 | 374 | |
| 370 | 375 | return hash('sha256', $this->bypass_level . $time . $this->cookie_key); |
| 371 | 376 | } |
| 372 | 377 | |
| @@ -381,18 +386,18 @@ | ||
| 381 | 386 | if (function_exists('is_user_logged_in') && is_user_logged_in()) { |
| 382 | 387 | $current_wp_user = $this->getCurrentWPUser(); |
| 383 | 388 | |
| 384 | 389 | if (!$current_wp_user->isIdentical($this->request->wp_user)) { |
| 385 | - $serialized_wp_user = WPRProtectWPUser_V556::_serialize($current_wp_user); | |
| 390 | + $serialized_wp_user = WPRProtectWPUser_V636::_serialize($current_wp_user); | |
| 386 | 391 | $cookie_val = $serialized_wp_user . '_' . |
| 387 | - WPRProtectUtils_V556::signMessage($serialized_wp_user, $this->cookie_key); | |
| 392 | + WPRProtectUtils_V636::signMessage($serialized_wp_user, $this->cookie_key); | |
| 388 | 393 | $cookie_val = base64_encode($cookie_val); |
| 389 | 394 | |
| 390 | - $this->setcookie(WPRProtectWPUser_V556::COOKIE_NAME, $cookie_val, time() + 43200); | |
| 395 | + $this->setCookie(WPRProtectWPUser_V636::COOKIE_NAME, $cookie_val); | |
| 391 | 396 | } |
| 392 | 397 | } elseif ($this->request->wp_user->isLoggedIn()) { |
| 393 | - $this->request->wp_user = WPRProtectWPUser_V556::defaultUser(); | |
| 394 | - $this->unsetCookie(WPRProtectWPUser_V556::COOKIE_NAME); | |
| 398 | + $this->request->wp_user = WPRProtectWPUser_V636::defaultUser(); | |
| 399 | + $this->unsetCookie(WPRProtectWPUser_V636::COOKIE_NAME); | |
| 395 | 400 | } |
| 396 | 401 | } |
| 397 | 402 | |
| 398 | 403 | private function getCurrentWPUser() { |
| @@ -398,9 +403,9 @@ | ||
| 398 | 403 | private function getCurrentWPUser() { |
| 399 | 404 | $id = 0; |
| 400 | 405 | $role_level = 0; |
| 401 | 406 | $capabilities = array(); |
| 402 | - $time = (int) floor(time() / 43200); | |
| 407 | + $time = (int) floor(time() / $this->cookie_validity); | |
| 403 | 408 | |
| 404 | 409 | if (function_exists('wp_get_current_user')) { |
| 405 | 410 | $user = wp_get_current_user(); |
| 406 | 411 | $id = $user->ID; |
| @@ -407,9 +412,9 @@ | ||
| 407 | 412 | $role_level = $this->getCurrentWPUserRoleLevel(); |
| 408 | 413 | $capabilities = $this->getCurrentWPUserCapabilities(); |
| 409 | 414 | } |
| 410 | 415 | |
| 411 | - return (new WPRProtectWPUser_V556($id, $role_level, $capabilities, $time)); | |
| 416 | + return (new WPRProtectWPUser_V636($id, $role_level, $capabilities, $time)); | |
| 412 | 417 | } |
| 413 | 418 | |
| 414 | 419 | private function getCurrentWPUserCapabilities() { |
| 415 | 420 | $capabilities = array(); |
| @@ -426,11 +431,11 @@ | ||
| 426 | 431 | return $capabilities; |
| 427 | 432 | } |
| 428 | 433 | |
| 429 | 434 | private function loadWPUser() { |
| 430 | - $this->request->wp_user = WPRProtectWPUser_V556::defaultUser(); | |
| 435 | + $this->request->wp_user = WPRProtectWPUser_V636::defaultUser(); | |
| 431 | 436 | |
| 432 | - $cookie_val = $this->request->getCookies(WPRProtectWPUser_V556::COOKIE_NAME); | |
| 437 | + $cookie_val = $this->request->getCookies(WPRProtectWPUser_V636::COOKIE_NAME); | |
| 433 | 438 | if (!is_string($cookie_val)) { |
| 434 | 439 | return; |
| 435 | 440 | } |
| 436 | 441 | |
| @@ -444,12 +449,12 @@ | ||
| 444 | 449 | return; |
| 445 | 450 | } |
| 446 | 451 | list($serialized_user, $signature) = $cookie_val_array; |
| 447 | 452 | |
| 448 | - if (WPRProtectUtils_V556::verifyMessage($serialized_user, $signature, $this->cookie_key) === true) { | |
| 449 | - $wp_user = WPRProtectWPUser_V556::_unserialize($serialized_user); | |
| 453 | + if (WPRProtectUtils_V636::verifyMessage($serialized_user, $signature, $this->cookie_key) === true) { | |
| 454 | + $wp_user = WPRProtectWPUser_V636::_unserialize($serialized_user); | |
| 450 | 455 | |
| 451 | - if (!isset($wp_user) || $wp_user->time !== (int) floor(time() / 43200)) { | |
| 456 | + if (!isset($wp_user) || $wp_user->time !== (int) floor(time() / $this->cookie_validity)) { | |
| 452 | 457 | return; |
| 453 | 458 | } |
| 454 | 459 | |
| 455 | 460 | $this->request->wp_user = $wp_user; |
| @@ -460,10 +465,10 @@ | ||
| 460 | 465 | $this->request->wp_user->capability_names[] = $capability_names[$capability]; |
| 461 | 466 | } |
| 462 | 467 | } |
| 463 | 468 | |
| 464 | - $role_by_level = array_flip(array_merge(WPRProtectFW_V556::DEFAULT_WP_USER_ROLE_LEVELS, | |
| 465 | - WPRProtectFW_V556::EXTRA_WP_USER_ROLE_LEVELS)); | |
| 469 | + $role_by_level = array_flip(array_merge(WPRProtectFW_V636::DEFAULT_WP_USER_ROLE_LEVELS, | |
| 470 | + WPRProtectFW_V636::EXTRA_WP_USER_ROLE_LEVELS)); | |
| 466 | 471 | $this->request->wp_user->role = $role_by_level[$this->request->wp_user->role_level]; |
| 467 | 472 | } |
| 468 | 473 | } |
| 469 | 474 | |
| @@ -485,11 +490,11 @@ | ||
| 485 | 490 | } |
| 486 | 491 | |
| 487 | 492 | if ($this->isPrependMode()) { |
| 488 | 493 | $rules_file = MCDATAPATH . MCCONFKEY . '-' . 'mc_rules.json'; |
| 489 | - $rule_arrays = WPRProtectUtils_V556::parseFile($rules_file); | |
| 494 | + $rule_arrays = WPRProtectUtils_V636::parseFile($rules_file); | |
| 490 | 495 | } else { |
| 491 | - $rule_arrays = WPRProtect_V556::$settings->getOption('bvruleset'); | |
| 496 | + $rule_arrays = WPRProtect_V636::$settings->getOption('bvruleset'); | |
| 492 | 497 | if(!is_array($rule_arrays)) { |
| 493 | 498 | $rule_arrays = array(); |
| 494 | 499 | } |
| 495 | 500 | } |
| @@ -499,9 +504,9 @@ | ||
| 499 | 504 | return; |
| 500 | 505 | } |
| 501 | 506 | |
| 502 | 507 | foreach($rule_arrays as $rule_array) { |
| 503 | - $rule = WPRProtectFWRule_V556::init($rule_array); | |
| 508 | + $rule = WPRProtectFWRule_V636::init($rule_array); | |
| 504 | 509 | |
| 505 | 510 | if ($rule) { |
| 506 | 511 | if (!$this->is_rule_initialized && $rule->isExeOnBoot()) { |
| 507 | 512 | if (!$this->isRequestHasValidBypassCookie()) { |
| @@ -570,9 +575,9 @@ | ||
| 570 | 575 | } else { |
| 571 | 576 | add_filter($hook_name, $callback, -9999999, $accepted_args); |
| 572 | 577 | } |
| 573 | 578 | } else { |
| 574 | - WPRProtectUtils_V556::preInitWPHook($hook_name, $callback, -9999999, $accepted_args); | |
| 579 | + WPRProtectUtils_V636::preInitWPHook($hook_name, $callback, -9999999, $accepted_args); | |
| 575 | 580 | } |
| 576 | 581 | } |
| 577 | 582 | |
| 578 | 583 | $this->pushWPFRule($function_name, $rule); |
| @@ -902,9 +907,13 @@ | ||
| 902 | 907 | $this->is_shutdown_cb_set = true; |
| 903 | 908 | } |
| 904 | 909 | } |
| 905 | 910 | |
| 906 | - private function setCookie($name, $value, $expire) { | |
| 911 | + private function setCookie($name, $value, $expire = null) { | |
| 912 | + if ($expire === null) { | |
| 913 | + $expire = time() + $this->cookie_validity; | |
| 914 | + } | |
| 915 | + | |
| 907 | 916 | $path = $this->cookie_path; |
| 908 | 917 | $cookie_domain = $this->cookie_domain; |
| 909 | 918 | |
| 910 | 919 | if (version_compare(PHP_VERSION, '5.2.0') >= 0) { |
| @@ -933,14 +942,14 @@ | ||
| 933 | 942 | } |
| 934 | 943 | |
| 935 | 944 | private function setIPCookie() { |
| 936 | 945 | if (!$this->is_ip_cookie_set && $this->isIPCookieEnabled() && |
| 937 | - !$this->request->getCookies(WPRProtectFW_V556::IP_COOKIE_NAME)) { | |
| 946 | + !$this->request->getCookies(WPRProtectFW_V636::IP_COOKIE_NAME)) { | |
| 938 | 947 | |
| 939 | 948 | $time = floor(time() / 86400); |
| 940 | 949 | $cookie = hash('sha256', $this->request->ip . $time . $this->cookie_key); |
| 941 | 950 | if ($cookie) { |
| 942 | - $this->setCookie(WPRProtectFW_V556::IP_COOKIE_NAME, $cookie, time() + 86400); | |
| 951 | + $this->setCookie(WPRProtectFW_V636::IP_COOKIE_NAME, $cookie, time() + 86400); | |
| 943 | 952 | } |
| 944 | 953 | } |
| 945 | 954 | } |
| 946 | 955 | |
| @@ -946,18 +955,18 @@ | ||
| 946 | 955 | |
| 947 | 956 | private function getCurrentWPUserRoleLevel() { |
| 948 | 957 | if (function_exists('current_user_can')) { |
| 949 | 958 | if (function_exists('is_super_admin') && is_super_admin()) { |
| 950 | - return WPRProtectFW_V556::WP_USER_ROLE_LEVEL_ADMIN; | |
| 959 | + return WPRProtectFW_V636::WP_USER_ROLE_LEVEL_ADMIN; | |
| 951 | 960 | } |
| 952 | 961 | |
| 953 | 962 | foreach ($this->custom_roles as $role) { |
| 954 | 963 | if (current_user_can($role)) { |
| 955 | - return WPRProtectFW_V556::WP_USER_ROLE_LEVEL_CUSTOM; | |
| 964 | + return WPRProtectFW_V636::WP_USER_ROLE_LEVEL_CUSTOM; | |
| 956 | 965 | } |
| 957 | 966 | } |
| 958 | 967 | |
| 959 | - foreach (WPRProtectFW_V556::DEFAULT_WP_USER_ROLE_LEVELS as $role => $level) { | |
| 968 | + foreach (WPRProtectFW_V636::DEFAULT_WP_USER_ROLE_LEVELS as $role => $level) { | |
| 960 | 969 | if (current_user_can($role)) { |
| 961 | 970 | return $level; |
| 962 | 971 | } |
| 963 | 972 | } |
| @@ -1063,11 +1072,11 @@ | ||
| 1063 | 1072 | |
| 1064 | 1073 | private function getBVCookies() { |
| 1065 | 1074 | $cookies = array(); |
| 1066 | 1075 | |
| 1067 | - if ($this->request->getCookies(WPRProtectFW_V556::IP_COOKIE_NAME) !== NULL) { | |
| 1068 | - $cookie_val = (string) $this->request->getCookies(WPRProtectFW_V556::IP_COOKIE_NAME); | |
| 1069 | - $cookies[WPRProtectFW_V556::IP_COOKIE_NAME] = $cookie_val; | |
| 1076 | + if ($this->request->getCookies(WPRProtectFW_V636::IP_COOKIE_NAME) !== NULL) { | |
| 1077 | + $cookie_val = (string) $this->request->getCookies(WPRProtectFW_V636::IP_COOKIE_NAME); | |
| 1078 | + $cookies[WPRProtectFW_V636::IP_COOKIE_NAME] = $cookie_val; | |
| 1070 | 1079 | } |
| 1071 | 1080 | |
| 1072 | 1081 | return $cookies; |
| 1073 | 1082 | } |
| @@ -1223,9 +1232,9 @@ | ||
| 1223 | 1232 | $this->updateRuleLog('inspect', "rawBody", $this->getRawBodyToLog($this->request->getRawBody())); |
| 1224 | 1233 | } |
| 1225 | 1234 | |
| 1226 | 1235 | private function getUserBy($attribute, $value) { |
| 1227 | - if (isset($value) && function_exists('get_user_by') && WPRProtectUtils_V556::havePluginsLoaded()) { | |
| 1236 | + if (isset($value) && function_exists('get_user_by') && WPRProtectUtils_V636::havePluginsLoaded()) { | |
| 1228 | 1237 | return get_user_by($attribute, $value); |
| 1229 | 1238 | } |
| 1230 | 1239 | } |
| 1231 | 1240 | |
| @@ -1327,9 +1336,9 @@ | ||
| 1327 | 1336 | xlsx|psd|mp3|m4a|ogg|wav|mp4|m4v|mov|wmv|avi|mpg|ogv|3gp|3g2|php|html|phtml|js|css)/ix', $value)) { |
| 1328 | 1337 | $profiled_data[$key]["file"] = true; |
| 1329 | 1338 | } |
| 1330 | 1339 | |
| 1331 | - if ($this->matchCount(WPRProtectFWRule_V556::SQLIREGEX, $value) > 2) { | |
| 1340 | + if ($this->matchCount(WPRProtectFWRule_V636::SQLIREGEX, $value) > 2) { | |
| 1332 | 1341 | $profiled_data[$key]["sql"] = true; |
| 1333 | 1342 | } |
| 1334 | 1343 | |
| 1335 | 1344 | if (WPRHelper::safePregMatch('/(?:\.{2}[\/]+)/', $value)) { |
| @@ -1406,15 +1415,15 @@ | ||
| 1406 | 1415 | } |
| 1407 | 1416 | |
| 1408 | 1417 | private function canRequestBypassFirewall() { |
| 1409 | 1418 | if ($this->isRequestIPWhitelisted() || $this->isRequestHasValidBypassCookie()) { |
| 1410 | - $this->request->category = WPRProtectRequest_V556::CATEGORY_WHITELISTED; | |
| 1411 | - $this->request->status = WPRProtectRequest_V556::STATUS_BYPASSED; | |
| 1419 | + $this->request->category = WPRProtectRequest_V636::CATEGORY_WHITELISTED; | |
| 1420 | + $this->request->status = WPRProtectRequest_V636::STATUS_BYPASSED; | |
| 1412 | 1421 | |
| 1413 | 1422 | return true; |
| 1414 | - } elseif (WPRProtectUtils_V556::isPrivateIP($this->request->ip)) { | |
| 1415 | - $this->request->category = WPRProtectRequest_V556::CATEGORY_PRIVATEIP; | |
| 1416 | - $this->request->status = WPRProtectRequest_V556::STATUS_BYPASSED; | |
| 1423 | + } elseif (WPRProtectUtils_V636::isPrivateIP($this->request->ip)) { | |
| 1424 | + $this->request->category = WPRProtectRequest_V636::CATEGORY_PRIVATEIP; | |
| 1425 | + $this->request->status = WPRProtectRequest_V636::STATUS_BYPASSED; | |
| 1417 | 1426 | |
| 1418 | 1427 | return true; |
| 1419 | 1428 | } |
| 1420 | 1429 | |
| @@ -1446,9 +1455,9 @@ | ||
| 1446 | 1455 | if (array_key_exists('variables', $rule->opts)) { |
| 1447 | 1456 | $_engine_vars = array_merge($_engine_vars, $rule->opts['variables']); |
| 1448 | 1457 | } |
| 1449 | 1458 | |
| 1450 | - $rule_engine = new WPRProtectFWRuleEngine_V556($this->request, $_engine_vars); | |
| 1459 | + $rule_engine = new WPRProtectFWRuleEngine_V636($this->request, $_engine_vars); | |
| 1451 | 1460 | |
| 1452 | 1461 | if ($rule_engine->evaluate($rule) && !$rule_engine->hasError()) { |
| 1453 | 1462 | if (!empty($log_data)) { |
| 1454 | 1463 | $this->updateRuleLog("info", (string) $rule->id, $log_data); |
| @@ -1459,13 +1468,13 @@ | ||
| 1459 | 1468 | foreach($rule->actions as $action) { |
| 1460 | 1469 | switch ($action["type"]) { |
| 1461 | 1470 | case "ALLOW": |
| 1462 | 1471 | $this->break_rule_matching = true; |
| 1463 | - $this->request->category = WPRProtectRequest_V556::CATEGORY_RULE_ALLOWED; | |
| 1472 | + $this->request->category = WPRProtectRequest_V636::CATEGORY_RULE_ALLOWED; | |
| 1464 | 1473 | return; |
| 1465 | 1474 | case "BLOCK": |
| 1466 | 1475 | if ($this->isModeProtect()) { |
| 1467 | - $this->terminateRequest(WPRProtectRequest_V556::CATEGORY_RULE_BLOCKED); | |
| 1476 | + $this->terminateRequest(WPRProtectRequest_V636::CATEGORY_RULE_BLOCKED); | |
| 1468 | 1477 | } |
| 1469 | 1478 | return; |
| 1470 | 1479 | case "INSPECT": |
| 1471 | 1480 | $this->inspectRequest(); |
| @@ -1479,15 +1488,15 @@ | ||
| 1479 | 1488 | } |
| 1480 | 1489 | |
| 1481 | 1490 | private function terminateRequest($category) { |
| 1482 | 1491 | $this->request->category = $category; |
| 1483 | - $this->request->status = WPRProtectRequest_V556::STATUS_BLOCKED; | |
| 1492 | + $this->request->status = WPRProtectRequest_V636::STATUS_BLOCKED; | |
| 1484 | 1493 | $this->request->setRespCode(403); |
| 1485 | 1494 | |
| 1486 | 1495 | if ($this->can_set_cache_prevention_cookie && |
| 1487 | - !$this->request->getCookies(WPRProtectFW_V556::PREVENT_CACHE_COOKIE_NAME)) { | |
| 1496 | + !$this->request->getCookies(WPRProtectFW_V636::PREVENT_CACHE_COOKIE_NAME)) { | |
| 1488 | 1497 | $value = "Prevent Caching Response."; |
| 1489 | - $this->setCookie(WPRProtectFW_V556::PREVENT_CACHE_COOKIE_NAME, $value, time() + 43200); | |
| 1498 | + $this->setCookie(WPRProtectFW_V636::PREVENT_CACHE_COOKIE_NAME, $value, time() + 43200); | |
| 1490 | 1499 | } |
| 1491 | 1500 | |
| 1492 | 1501 | header("Cache-Control: no-cache, no-store, must-revalidate"); |
| 1493 | 1502 | header("Pragma: no-cache"); |
| @@ -1492,8 +1501,9 @@ | ||
| 1492 | 1501 | header("Cache-Control: no-cache, no-store, must-revalidate"); |
| 1493 | 1502 | header("Pragma: no-cache"); |
| 1494 | 1503 | header("Expires: 0"); |
| 1495 | 1504 | header('HTTP/1.0 403 Forbidden'); |
| 1505 | + // phpcs:disable WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 1496 | 1506 | die(" |
| 1497 | 1507 | <div style='height: 98vh;'> |
| 1498 | 1508 | <div style='text-align: center; padding: 10% 0; font-family: Arial, Helvetica, sans-serif;'> |
| 1499 | 1509 | <div><p>" . $this->brand_name . " Firewall</p></div> |
| @@ -1501,8 +1511,9 @@ | ||
| 1501 | 1511 | <p>Reference ID: " . $this->request->getRequestID() . "</p> |
| 1502 | 1512 | </div> |
| 1503 | 1513 | </div> |
| 1504 | 1514 | "); |
| 1515 | + // phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 1505 | 1516 | } |
| 1506 | 1517 | |
| 1507 | 1518 | public function setBypassCookie() { |
| 1508 | 1519 | if (function_exists('is_user_logged_in') && is_user_logged_in() && |
| @@ -1511,9 +1522,9 @@ | ||
| 1511 | 1522 | $role_level = $this->getCurrentWPUserRoleLevel(); |
| 1512 | 1523 | if ($role_level >= $this->bypass_level) { |
| 1513 | 1524 | $cookie = $this->generateBypassCookie(); |
| 1514 | 1525 | if ($cookie) { |
| 1515 | - $this->setCookie(WPRProtectFW_V556::BYPASS_COOKIE_NAME, $cookie, time() + 43200); | |
| 1526 | + $this->setCookie(WPRProtectFW_V636::BYPASS_COOKIE_NAME, $cookie); | |
| 1516 | 1527 | } |
| 1517 | 1528 | } |
| 1518 | 1529 | } |
| 1519 | 1530 | } |