Skip to content

Commit

Permalink
Fix. Admin. Cookies logged_in fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Glomberg committed Apr 12, 2024
1 parent c1393ca commit cac836b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
12 changes: 10 additions & 2 deletions inc/spbc-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,16 @@ function spbc_admin_init()
}

// Set cookie to detect admin on public pages
if ( ! empty($spbc->settings['data__set_cookies']) && ! Cookie::get('spbc_admin_logged_in') && is_admin() && current_user_can('manage_options') ) {
Cookie::set('spbc_admin_logged_in', md5($spbc->data['salt'] . 'admin' . parse_url(get_option('home'), PHP_URL_HOST)), time() + 86400 * 365, '/');
if (
! empty($spbc->settings['data__set_cookies']) &&
(
! Cookie::get('spbc_admin_logged_in') ||
Cookie::get('spbc_admin_logged_in') !== md5($spbc->data['salt'] . 'admin' . get_option('home'))
) &&
is_admin() &&
current_user_can('manage_options')
) {
Cookie::set('spbc_admin_logged_in', md5($spbc->data['salt'] . 'admin' . get_option('home')), time() + 86400 * 365, '/');
}
}

Expand Down
23 changes: 15 additions & 8 deletions security-malware-firewall.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,15 @@ function spbc_set_headers()
}

// Set cookie to detect any logged in user
if ( spbc_is_user_logged_in() && ! empty($spbc->settings['data__set_cookies']) && ! Cookie::get('spbc_is_logged_in') ) {
Cookie::set('spbc_is_logged_in', md5($spbc->data['salt'] . parse_url(get_option('home'), PHP_URL_HOST)), time() + 86400 * 365, '/');
if (
spbc_is_user_logged_in() &&
! empty($spbc->settings['data__set_cookies']) &&
(
! Cookie::get('spbc_is_logged_in') ||
Cookie::get('spbc_is_logged_in') !== md5($spbc->data['salt'] . get_option('home'))
)
) {
Cookie::set('spbc_is_logged_in', md5($spbc->data['salt'] . get_option('home')), time() + 86400 * 365, '/');
}
}
}
Expand Down Expand Up @@ -527,7 +534,7 @@ function spbc_firewall__check()
'log_table' => SPBC_TBL_TC_LOG,
'state' => $spbc,
'api_key' => $spbc->api_key,
'is_logged_in' => Cookie::get('spbc_is_logged_in') === md5($spbc->data['salt'] . parse_url(get_option('home'), PHP_URL_HOST)),
'is_logged_in' => Cookie::get('spbc_is_logged_in') === md5($spbc->data['salt'] . get_option('home')),
'user_is_admin' => spbc_user_is_admin(),
'store_interval' => $spbc->settings['traffic_control__autoblock_timeframe'],
'tc_limit' => $spbc->settings['traffic_control__autoblock_amount'],
Expand All @@ -548,7 +555,7 @@ function spbc_firewall__check()
];
if ( $spbc->settings['waf_blocker__enabled'] ) {
$waf_blocker_params = [
'is_logged_in' => Cookie::get('spbc_is_logged_in') === md5($spbc->data['salt'] . parse_url(get_option('home'), PHP_URL_HOST)),
'is_logged_in' => Cookie::get('spbc_is_logged_in') === md5($spbc->data['salt'] . get_option('home')),
'db' => DB::getInstance(),
'ip_array' => $firewall->ip_array
];
Expand Down Expand Up @@ -577,7 +584,7 @@ function spbc_firewall__check()
'api_key' => $spbc->api_key,
'state' => $spbc,
'is_login_page' => strpos(trim(Server::getURL(), '/'), trim($login_url, '/')) === 0,
'is_logged_in' => Cookie::get('spbc_is_logged_in') === md5($spbc->data['salt'] . parse_url(get_option('home'), PHP_URL_HOST)),
'is_logged_in' => Cookie::get('spbc_is_logged_in') === md5($spbc->data['salt'] . get_option('home')),
'bf_limit' => $spbc->settings['bfp__allowed_wrong_auths'],
'block_period' => $spbc->settings['bfp__block_period__5_fails'],
'count_period' => $spbc->settings['bfp__count_interval'], // Counting login attempts in this interval
Expand Down Expand Up @@ -689,7 +696,7 @@ function spbc_authenticate__check_brute_force()
'api_key' => $spbc->api_key,
'state' => $spbc,
'is_login_page' => strpos(trim(Server::getURL(), '/'), trim($login_url, '/')) === 0,
'is_logged_in' => Cookie::get('spbc_is_logged_in') === md5($spbc->data['salt'] . parse_url(get_option('home'), PHP_URL_HOST)),
'is_logged_in' => Cookie::get('spbc_is_logged_in') === md5($spbc->data['salt'] . get_option('home')),
'bf_limit' => $spbc->settings['bfp__allowed_wrong_auths'],
'block_period' => $spbc->settings['bfp__block_period__5_fails'],
'count_period' => $spbc->settings['bfp__count_interval'],
Expand Down Expand Up @@ -1023,8 +1030,8 @@ function spbc_user_is_admin()

if (!empty($spbc->settings['data__set_cookies'])) {
return
Cookie::get('spbc_is_logged_in') === md5($spbc->data['salt'] . parse_url(get_option('home'), PHP_URL_HOST)) &&
Cookie::get('spbc_admin_logged_in') === md5($spbc->data['salt'] . 'admin' . parse_url(get_option('home'), PHP_URL_HOST));
Cookie::get('spbc_is_logged_in') === md5($spbc->data['salt'] . get_option('home')) &&
Cookie::get('spbc_admin_logged_in') === md5($spbc->data['salt'] . 'admin' . get_option('home'));
}

return is_admin();
Expand Down

0 comments on commit cac836b

Please sign in to comment.