Timeout on password change

pennymachines
w3 User
w3 User
Posts: 115
Joined: Mon Feb 06, 2017 9:51 pm

Re: Timeout on password change

Post by pennymachines »

Hi,

Thank you for the quick update. As you asked, I re-tested after updating, counting how often wp_check_password() runs and which hooks with w3all callbacks run more than once. The site is live and behind Cloudflare. wp-login.php, the membership pages and logged-in requests bypass the cache, so these results are not distorted by caching. The 524 below is Cloudflare's 100 s limit; PHP carried on and finished.

ENVIRONMENT
WordPress Multisite (subdirectory) version 7.1.5, PHP version 8.3.36, phpBB version 3.3.15, w3all version 3.2.5. Simple Membership, Wordfence and Post SMTP are also active. The host is shared with a slow CPU (about 4-6 s page boot).

METHOD
A temporary mu-plugin counts, per request: calls to wp_check_password() (and who made them), hooks that have w3all callbacks and ran more than once, and phpBB queries and their time. It logs counts and hook or function names only.

RESULTS

1. Login at /arena/wp-login.php (PHP time 7.64 s)
- wp_check_password() calls: 3
- SwpmAuth::check_password, simple-membership class.swpm-auth.php:403 (1)
- WP_w3all_phpbb::w3_check_phpbb_profile_wpnu, class.wp.w3all-phpbb.php:2372 (1)
- wp_w3all_login_existent_phpbb_fix, functions.php:1177 (1)
- phpBB queries: 13 in 0.35 s
- No w3all hook ran more than once.
Two of the three calls come from w3all. If both are needed for this login, fine. If not, one may still be redundant. I have no before-update measurement for login, so I can't say how much your fix improved it.

2. Password change via the front-end profile form, Wordfence's "Check password strength on profile update" OFF (PHP time 8.98 s)
- wp_check_password() calls: 0
- phpBB queries: 6 in 0.11 s
- Hook running repeatedly: auth_cookie_expiration, 4 times (callback w3all_rememberme_long, priority 10). It ran 3 times in another run. This looks cheap, but you may want to check whether the auth cookie is being set several times per request.

3. Same password change with that Wordfence option ON (PHP time 214.1 s, Cloudflare 524 at about 2 m 08 s)
- wp_check_password() calls: 86, all from wfScanEngine::scanUserPassword (wordfence/lib/wfScanEngine.php:1681)
- phpBB queries: 94 in 9.55 s in total, of which 86 are SELECT user_password, user_email FROM phpbb_users WHERE LOWER(user_email) = ?
- This is unchanged from before the update (86 calls, 94 queries, 222-299 s).

OBSERVATIONS
- In case 3 the 86 calls test different candidate passwords against the same stored hash, so removing duplicate calls would not reduce the count. The per-call cost would have to come down.
- Each call takes about 2.5 s here (214 s / 86). The phpBB queries account for only about 0.11 s per call, so the remaining 2.4 s or so is spent elsewhere in the override. My earlier timing showed the delay falls before the apply_filters('check_password') call at wp_w3all.php:572.
- Questions: what does the override do before that point on each call? Could repeated calls for the same user within one request avoid the phpBB lookup (for example a per-request cache keyed by user ID), or skip it when the call is not part of a login?

Workaround in place: I've turned the Wordfence option off.

Thank you again.
User avatar
axew3
w3all User
w3all User
Posts: 3110
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Skype: axewww

Re: Timeout on password change

Post by axew3 »

Two of the three calls come from w3all. If both are needed for this login, fine. If not, one may still be redundant. I have no before-update measurement for login, so I can't say how much your fix improved it.
Applied the new code, no matter how many times it is called, it do not compute nothing and just return the result executed only the first time. Same goes for w3_check_phpbb_profile_wpnu.

Can we do the same for the main verify_phpbb_credentials() let test it.
User avatar
axew3
w3all User
w3all User
Posts: 3110
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Skype: axewww

Re: Timeout on password change

Post by axew3 »

The most simple way can be

On top of the
private static function verify_phpbb_credentials(){
there is this code:

Code: Select all

# if it is defined WPW3ALL_ULOGGED_NOPHPBBCREDENTIALS
  if( defined('WPW3ALL_ULOGGED_NOPHPBBCREDENTIALS') && is_user_logged_in() ) return;
change into:

Code: Select all

  # If it is defined WPW3ALL_ULOGGED_NOPHPBBCREDENTIALS
  # And to run only once using W3PHPBBCREDENTIALSEXEC
  if( defined('W3PHPBBCREDENTIALSEXEC') OR defined('WPW3ALL_ULOGGED_NOPHPBBCREDENTIALS') && is_user_logged_in() ) return;

  define('W3PHPBBCREDENTIALSEXEC', true);
User avatar
axew3
w3all User
w3all User
Posts: 3110
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Skype: axewww

Re: Timeout on password change

Post by axew3 »

Beside the above, that stop
private static function verify_phpbb_credentials(){
to exec more than one time when wordpress loads, i note that we also have to change probably the plugin code into this:

wp_w3all.php
line 221

Code: Select all

add_action( 'init', array( 'WP_w3all_phpbb', 'wp_w3all_phpbb_init' ), 3 );
changed into:

Code: Select all

add_action( 'admin_init', array( 'WP_w3all_phpbb', 'wp_w3all_phpbb_init' ), 3 );
then, on file class.wp.w3all-phpbb.php

this code:

Code: Select all

public static function wp_w3all_phpbb_init() {

  global $phpbb_config,$w3all_get_phpbb_avatar_yn;
should be changed into:

Code: Select all

public static function wp_w3all_phpbb_init() {

    if ( is_admin() && wp_doing_ajax() || wp_doing_cron() ) return;

  global $phpbb_config,$w3all_get_phpbb_avatar_yn;
Now i see that the private static function verify_phpbb_credentials(){
run always only once, if i am not wrong.

I will check to add more optimizations before to release next coming version.
Any suggestion!?