PluginProbe
Patchstack – WordPress & Plugins Security / 2.2.6
Patchstack – WordPress & Plugins Security v2.2.6
2.3.7 trunk 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.16 2.1.17 2.1.18 2.1.19 2.1.2 2.1.20 2.1.21 2.1.22 2.1.23 2.1.24 2.1.25 2.1.3 2.1.4 2.1.5 2.1.6 All 49 releases
← All changes | includes/hide-login.php +27 -11 2.1.142.2.6 View file →
@@ -32,10 +32,10 @@
32 32 return;
33 33 }
34 34
35 35 // Register the filters and actions for the functionality.
36 - add_action( 'init', array( $this, 'init' ) );
37 - add_action( 'wp_logout', array( $this, 'wp_logout' ) );
36 + add_action( 'init', [ $this, 'init' ], ~PHP_INT_MAX + 1 );
37 + add_action( 'wp_logout', [ $this, 'wp_logout' ] );
38 38 }
39 39
40 40 /**
41 41 * Deny access to wp-login.php if the login page rename feature is enabled.
@@ -48,16 +48,32 @@
48 48 return;
49 49 }
50 50
51 51 // Determine if the user is whitelisted.
52 - if ( ( stripos( $_SERVER['REQUEST_URI'], 'wp-login.php' ) !== false || $GLOBALS['pagenow'] === 'wp-login.php' || $_SERVER['PHP_SELF'] === '/wp-login.php' ) && !$this->is_whitelisted() ) {
52 + if ( ( stripos( $_SERVER['REQUEST_URI'], 'wp-login.php' ) !== false || $GLOBALS['pagenow'] === 'wp-login.php' || $_SERVER['PHP_SELF'] === '/wp-login.php' ) && ! $this->is_whitelisted() ) {
53 + if ( isset( $_REQUEST['action'] ) && in_array( $_REQUEST['action'], ['confirm_admin_email', 'postpass', 'lostpassword', 'retrievepassword', 'resetpass', 'rp', 'register', 'checkemail', 'confirmaction'] ) ) {
54 + return;
55 + }
56 +
53 57 $this->plugin->firewall_base->display_error_page( 'login' );
54 58 }
55 59
56 60 // If the current page is the renamed login page we give the user access for 10 minutes to the login page.
57 61 if ( strpos( $_SERVER['REQUEST_URI'], get_site_option( 'patchstack_rename_wp_login' ) ) !== false ) {
62 + // Whitelist the current IP address.
58 63 $this->whitelist_ip();
59 - wp_safe_redirect( 'wp-login.php' );
64 +
65 + // Supported by a number of popular caching plugins.
66 + if ( ! defined( 'DONOTCACHEPAGE' ) ) {
67 + define( 'DONOTCACHEPAGE', true );
68 + }
69 +
70 + // No caching.
71 + send_nosniff_header();
72 + nocache_headers();
73 +
74 + // User should be whitelisted now, redirect to the login page.
75 + wp_safe_redirect( 'wp-login.php', 307 );
60 76 exit;
61 77 }
62 78 }
63 79
@@ -76,10 +92,10 @@
76 92 * @return boolean
77 93 */
78 94 private function is_whitelisted() {
79 95 // Process the whitelist, and remove old ones.
80 - $whitelist = get_site_option( 'patchstack_rename_wp_login_whitelist', array() );
81 - $new_whitelist = array();
96 + $whitelist = get_site_option( 'patchstack_rename_wp_login_whitelist', [] );
97 + $new_whitelist = [];
82 98 $allow = false;
83 99
84 100 // Only continue if there are actually any whitelist entries.
85 101 if ( is_array( $whitelist ) && count( $whitelist ) != 0 ){
@@ -108,10 +124,10 @@
108 124 *
109 125 * @return void
110 126 */
111 127 private function whitelist_ip() {
112 - $whitelist = get_site_option( 'patchstack_rename_wp_login_whitelist', array() );
113 - $new_whitelist = array();
128 + $whitelist = get_site_option( 'patchstack_rename_wp_login_whitelist', [] );
129 + $new_whitelist = [];
114 130
115 131 // If the IP address is already whitelisted, reset the timestamp.
116 132 if ( is_array( $whitelist ) && count( $whitelist ) != 0 ) {
117 133 $ip = $this->get_ip();
@@ -118,9 +134,9 @@
118 134 $whitelisted = false;
119 135 foreach ( $whitelist as $entry ) {
120 136 // Determine if we should extend the whitelist time or ignore if already whitelisted.
121 137 if ( $ip === $entry[0] ) {
122 - $new_whitelist[] = array( $ip, time() );
138 + $new_whitelist[] = [ $ip, time() ];
123 139 $whitelisted = true;
124 140 } else {
125 141 $new_whitelist[] = $entry;
126 142 }
@@ -127,13 +143,13 @@
127 143 }
128 144
129 145 // Whitelist the IP address.
130 146 if ( ! $whitelisted ) {
131 - $new_whitelist[] = array( $ip, time() );
147 + $new_whitelist[] = [ $ip, time() ];
132 148 }
133 149
134 150 update_site_option( 'patchstack_rename_wp_login_whitelist', $new_whitelist );
135 151 } else {
136 - update_site_option( 'patchstack_rename_wp_login_whitelist', array( array( $this->get_ip(), time() ) ) );
152 + update_site_option( 'patchstack_rename_wp_login_whitelist', [ [ $this->get_ip(), time() ] ] );
137 153 }
138 154 }
139 155 }