Changeset 3410794
- Timestamp:
- 12/04/2025 11:28:25 AM (9 days ago)
- Location:
- sg-security/trunk
- Files:
-
- 6 edited
-
core/Activity_Log/Activity_Log.php (modified) (1 diff)
-
core/Custom_Login_Url/Custom_Login_Url.php (modified) (16 diffs)
-
core/Loader/Loader.php (modified) (1 diff)
-
core/Login_Service/Login_Service.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
-
sg-security.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sg-security/trunk/core/Activity_Log/Activity_Log.php
r3149177 r3410794 178 178 1 === Helper_Service::is_cron_disabled() 179 179 ) { 180 if ( ! current_user_can( 'manage_options' ) ) { 181 wp_die( 182 esc_html__( 'You don’t have access to this page. Please contact the administrator of this website for further assistance.', 'sg-security' ), 183 esc_html__( 'Restricted access', 'sg-security' ), 184 array( 185 'sgs_error' => true, 186 'response' => 403, 187 ) 188 ); 189 } 190 180 191 $this->delete_old_activity_logs(); 181 192 } -
sg-security/trunk/core/Custom_Login_Url/Custom_Login_Url.php
r3165493 r3410794 25 25 */ 26 26 private $options = array(); 27 28 /** 29 * Flag for the ultimate-member plugin forms. 30 * 31 * @var boolean 32 */ 33 private $um_form_detected_error = false; 27 34 28 35 /** … … 41 48 42 49 /** 43 * Change the site url to include the custom login urltoken,50 * Change the site URL to include the custom login URL token, 44 51 * 45 52 * @param string $url The URL to be filtered. … … 54 61 $path = Helper::get_url_path( $path ); //phpcs:ignore 55 62 56 preg_match( '~^(.*)\/(wp-login.php)(?:.*)?[\?|&]action=(.*?)(?:\?|&|$)~', $path, $matches ); 57 58 if ( empty( $matches[2] ) ) { 63 if ( strpos( $path, 'wp-login.php' ) === false ) { 59 64 return $url; 60 65 } 61 66 62 if ( empty( $matches[3] ) ) { 63 return $url; 64 } 65 66 switch ( $matches[3] ) { 67 case 'postpass': 68 return $url; 69 case 'register': 70 $token = 'register'; 71 break; 72 case 'rp': 73 $token = 'login'; 74 return $url; 75 } 76 77 // Add the token to the url if not empty. 67 if ( preg_match( '~[\?&]action=([^&]*)~', $path, $matches ) ) { 68 switch ( $matches[1] ) { 69 case 'postpass': 70 return $url; 71 case 'register': 72 $token = 'register'; 73 break; 74 case 'rp': 75 return $url; 76 } 77 } else if ( 78 isset( $_GET[ $this->token ] ) && 79 $_GET[ $this->token ] === $this->options['new_slug'] 80 ) { 81 $token = $this->options['new_slug']; 82 } 83 84 // Add the token to the URL if not empty. 78 85 if ( empty( $token ) ) { 79 86 return $url; 80 87 } 81 88 82 // Return the url.89 // Return the URL. 83 90 return add_query_arg( $this->token, urlencode( $token ), $url ); 84 91 } … … 103 110 */ 104 111 public function handle_request() { 112 105 113 // Get the path. 106 114 $path = Helper::get_url_path( $_SERVER['REQUEST_URI'] ); //phpcs:ignore … … 110 118 } 111 119 120 // Check if we are redirected to the login page, by the LogIn button on the registration page. 121 if ( 122 $this->is_valid( 'login' ) && 123 isset( $_SERVER['HTTP_REFERER'] ) && 124 false !== strpos( $_SERVER['HTTP_REFERER'], 'register' ) && 125 false !== strpos( $path, 'wp-login.php' ) 126 ) { 127 $this->redirect_with_token( 'login', 'wp-login.php' ); 128 } 129 130 // Check if we are redirected to the registration page, by the Register button on the login page. 131 if ( 132 $this->is_valid( 'login' ) && 133 isset( $_SERVER['HTTP_REFERER'] ) && 134 false !== strpos( $_SERVER['HTTP_REFERER'], $this->options['new_slug'] ) && 135 isset( $_GET['action'] ) && 'register' === $_GET['action'] 136 ) { 137 $this->handle_registration(); 138 } 139 112 140 if ( false !== strpos( $path, 'wp-login' ) || false !== strpos( $path, 'wp-login.php' ) ) { 113 141 $this->handle_login(); … … 117 145 $this->handle_registration(); 118 146 } 119 120 147 } 121 148 … … 139 166 140 167 /** 141 * Adds a token and redirect to the url.168 * Adds a token and redirect to the URL. 142 169 * 143 170 * @since 1.1.0 … … 155 182 156 183 $url = add_query_arg( $query_vars, site_url( $path ) ); 184 185 // Get the current URL. 186 $current_url = ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http' ) . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 187 188 // Prevent redirect loop by checking if the current URL matches the redirect URL. 189 if ( true === $this->compare_urls( $url, $current_url ) ) { 190 return; 191 } 157 192 158 193 wp_redirect( $url ); … … 196 231 197 232 if ( 'jetpack-sso' === $action && has_filter( 'login_form_jetpack-sso' ) ) { 198 // Jetpack's SSO redirects from wordpress.com to wp-login.php on the site. Only allow this process to233 // Jetpack's SSO redirects from WordPress.com to wp-login.php on the site. Only allow this process to 199 234 // continue if they successfully log in, which should happen by login_init in Jetpack which happens just 200 235 // before this action fires. … … 293 328 294 329 /** 295 * Handle reg ostration request.330 * Handle registration request. 296 331 * 297 332 * @since 1.1.0 … … 344 379 */ 345 380 public function show_notices() { 346 // Bail if we sho ld not show the notice.381 // Bail if we should not show the notice. 347 382 if ( empty( get_option( 'sg_security_show_signup_notice', false ) ) ) { 348 383 return; … … 391 426 392 427 /** 393 * Adds the login token to the confirmation url.428 * Adds the login token to the confirmation URL. 394 429 * 395 430 * @since 1.1.1 … … 409 444 } 410 445 411 // Add the login token to the GDPR confirmation url.446 // Add the login token to the GDPR confirmation URL. 412 447 $confirm_url = add_query_arg( 413 448 $this->token, … … 451 486 * @since 1.3.3 452 487 * 453 * @param \WP_User $user \WP_User object of the user that is trying to login.488 * @param \WP_User |\WP_Error $user \WP_User object of the user that is trying to login or \WP_Error object if a previous callback failed * authentication. 454 489 * @return \WP_Error|\WP_User If successful, the original \WP_User object, otherwise a \WP_Error object. 455 490 */ 456 491 public function maybe_block_custom_login( $user ) { 457 // Check if the refer er slug is set.492 // Check if the referrer slug is set. 458 493 if ( ! isset( $_SERVER['HTTP_REFERER'] ) ) { 494 return $user; 495 } 496 497 // Check if $user is a WP_Error object. 498 if ( is_wp_error( $user ) ) { 499 return $user; 500 } 501 502 // Check if the ultimate member plugin form has errors. 503 if ( true === $this->um_form_detected_error ) { 459 504 return $user; 460 505 } … … 470 515 } 471 516 472 // Get refer er parts by parsing its url.517 // Get referrer parts by parsing its URL. 473 518 $referer = str_replace( 474 519 array( home_url(), '/' ), … … 500 545 return $error; 501 546 } 547 548 /** 549 * Adds our 'maybe_block_custom_login' error message, in the Ultimate Member plugin's errors filter. 550 * 551 * @param $err_codes Custom error codes array on the ultimate members plugin forms. 552 * 553 * @return $err_codes The updated error codes array. 554 */ 555 public function add_um_form_error_code( $err_codes ) { 556 // Adds our error message code. 557 $err_codes[] = 'authentication_failed'; 558 559 return $err_codes; 560 } 561 562 /** 563 * Sets the flag, if the ultimate member plugin find error on their forms. 564 * 565 * @param $error The error message. 566 * 567 * @param $key The error code. 568 * 569 * @return $error The error message. 570 */ 571 public function set_um_form_flag( $error, $key ) { 572 // Check if the UM form has detected and error. 573 if ( $key ) { 574 $this->um_form_detected_error = true; 575 } 576 577 return $error; 578 } 579 580 /** 581 * Adds the 'sgs-token' query string after language change. 582 */ 583 public function add_sgs_token_to_language_switcher() { 584 // Check if the language of the login/register pages is getting changed. 585 if ( 586 $this->is_valid( 'login' ) && 587 isset( $_SERVER['HTTP_REFERER'] ) && 588 ( 589 false !== strpos( $_SERVER['HTTP_REFERER'], $this->options['new_slug'] ) || 590 false !== strpos( $_SERVER['HTTP_REFERER'], $this->options['register'] ) 591 ) && 592 isset( $_GET['wp_lang'] ) 593 ) { 594 595 // Get the current URL. 596 $current_url = ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http' ) . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; 597 598 $parsed_url = wp_parse_url( $current_url ); 599 600 // Extract query parameters from the URL. 601 $query_params = array(); 602 if ( isset( $parsed_url['query'] ) ) { 603 parse_str( $parsed_url['query'], $query_params ); 604 } 605 606 // Determine which SGS token to add. Preset it to 'register'. 607 $query_params['sgs-token'] = $this->options['register']; 608 609 if ( false !== strpos( $_SERVER['HTTP_REFERER'], $this->options['new_slug'] ) ) { 610 $query_params['sgs-token'] = $this->options['new_slug']; 611 } 612 613 // Sanitize all query parameters. 614 foreach ( $query_params as $key => $value ) { 615 $query_params[ $key ] = sanitize_text_field( $value ); 616 } 617 618 // Build the URL with all the parameters. 619 $redirect_url = add_query_arg( $query_params, site_url( 'wp-login.php' ) ); 620 621 // Prevent redirect loop by checking if the current URL matches the redirect URL. 622 if ( true === $this->compare_urls( $current_url, $redirect_url ) ) { 623 return; 624 } 625 626 wp_safe_redirect( $redirect_url ); 627 exit; 628 } 629 } 630 631 /** 632 * Compare two URLs if they are basically the same. 633 * 634 * @param $current_url First URL to compare. 635 * 636 * @param $redirect_url Second URL to compare. 637 * 638 * @return boolean True if the URLs are the same. False if they are different. 639 */ 640 public function compare_urls( $current_url, $redirect_url ) { 641 // Parse the URLs 642 $current_url = parse_url( $current_url ); 643 $redirect_url = parse_url( $redirect_url ); 644 645 // Check if both URLs have the same domain. 646 if ( $current_url['host'] !== $redirect_url['host'] ) { 647 return false; 648 } 649 650 // Ensure both URLs include "wp-login.php" in the path. 651 if ( false === strpos( $current_url['path'], 'wp-login.php' ) || false === strpos( $redirect_url['path'], 'wp-login.php' ) ) { 652 return false; 653 } 654 655 // Parse query strings into arrays for comparison. 656 parse_str( $current_url['query'], $current_url_params ); 657 parse_str( $redirect_url['query'], $redirect_url_params ); 658 659 // Compare the total number of query parameters. 660 if ( count( $current_url_params ) !== count( $redirect_url_params ) ) { 661 return false; 662 } 663 664 // If a key is missing or a value is different, URLs are not equal. 665 foreach ( $current_url_params as $query_key => $query_value ) { 666 if ( 667 ! array_key_exists( $query_key, $redirect_url_params ) || 668 $redirect_url_params[ $query_key ] !== $query_value 669 ) { 670 return false; 671 } 672 } 673 674 return true; 675 } 502 676 } -
sg-security/trunk/core/Loader/Loader.php
r3142129 r3410794 292 292 add_filter( 'wpdiscuz_login_link', array( $this->custom_login_url, 'custom_login_for_wpdiscuz' ) ); 293 293 add_action( 'wp_authenticate_user', array( $this->custom_login_url, 'maybe_block_custom_login' ) ); 294 add_action( 'login_init', array( $this->custom_login_url, 'add_sgs_token_to_language_switcher' ) ); 295 add_filter( 'um_custom_authenticate_error_codes', array( $this->custom_login_url, 'add_um_form_error_code' ) ); 296 add_filter( 'um_submit_form_error', array( $this->custom_login_url, 'set_um_form_flag' ), 100, 2 ); 294 297 } 295 298 -
sg-security/trunk/core/Login_Service/Login_Service.php
r2904929 r3410794 42 42 */ 43 43 public function restrict_login_to_ips() { 44 // Bail if the user is trying to access password protected page. 45 if ( isset( $_POST['post_password'] ) && ! is_admin() ) { //phpcs:ignore 46 return true; 47 } 48 44 49 // Get the list of allowed IP addresses. 45 50 $allowed_ips = get_option( 'sg_login_access', array() ); -
sg-security/trunk/readme.txt
r3273083 r3410794 3 3 Tags: security, firewall, malware scanner, web application firewall, login 4 4 Requires at least: 4.7 5 Tested up to: 6. 85 Tested up to: 6.9 6 6 Requires PHP: 7.0 7 Stable tag: 1.5. 77 Stable tag: 1.5.8 8 8 License: GPLv3 9 9 License URI: http://www.gnu.org/licenses/gpl-3.0.html … … 144 144 145 145 == Changelog == 146 = Version 1.5.8 = 147 Release Date Dec 4th, 2025 148 149 * Custom Login improvements 150 * Login Security improvements 151 * Security improvements 152 146 153 = Version 1.5.7 = 147 154 Release Date Nov 21st, 2024 -
sg-security/trunk/sg-security.php
r3194231 r3410794 11 11 * Plugin URI: https://siteground.com 12 12 * Description: Security Optimizer by SiteGround is the all-in-one security solution for your WordPress website. With the carefully selected and easy to configure functions the plugin provides everything you need to secure your website and prevent a number of threats such as brute-force attacks, compromised login, data leaks and more. 13 * Version: 1.5. 713 * Version: 1.5.8 14 14 * Author: SiteGround 15 15 * Author URI: https://www.siteground.com … … 33 33 // Define version constant. 34 34 if ( ! defined( __NAMESPACE__ . '\VERSION' ) ) { 35 define( __NAMESPACE__ . '\VERSION', '1.5. 7' );35 define( __NAMESPACE__ . '\VERSION', '1.5.8' ); 36 36 } 37 37
Note: See TracChangeset
for help on using the changeset viewer.