• Resolved ymca

    (@ymca)


    Hi,

    I have this plugin in the site:
    https://wordpress.org/plugins/user-blocker/

    When I have activated it and tried to log to the “/wp-login”, it gave me these errors:
    https://wordpress.org/support/topic/multi-errors-after-activating-plugin/

    Now I have returened to the plugin and reactivated it and got this error without the old errors:

    Warning: get_class() expects parameter 1 to be object, boolean given in /wp-content/plugins/wordfence/lib/wordfenceClass.php on line 1976

    I have no idea what is wrong.

    p.s.

    wordpress login page also shows an error:
    “ERROR: Cookies are blocked due to unexpected output. For help, please see this documentation or try the support forums.”

    • This topic was modified 6 years, 8 months ago by ymca.
Viewing 6 replies - 1 through 6 (of 6 total)
  • The root-cause (what ultimately started the failure) is not in WordFence, but in the User-Blocker plugin. Poor coding can cause User-Blocker to at times pass on values that should not exist in the authentication path.

    @solwininfotech’s answer from earlier of simply passing you on to the next layer in the filter chain was wrong. They did not actually look at the problem before throwing it “over the fence” to WordFence.

    Their code has an obvious flaw. 2 minutes or less of looking at their code should tell them where it can go haywire.

    You have hit one of the unfortunate side-effects of having multiple plugins trying to manipulate the same thing.

    That said, I would suggest a tiny future improvement in WordFence, where it validates whether other plugins might pass them unexpected/invalid values. That would prevent the PHP errors from being reported in WordFence.
    That would not fix the root-flaw, though. That must come from User-Blocker.

    Hi @ymca
    It seems that “user-blocker” plugin has a function that is hooked to WordPress’s “authenticate” filter, in Wordfence -around line 1976 in wordfenceClass.php as reported- we have a function that is hooked to the same filter, it seems that the function in “user-blocker” plugin is running first and it’s returning unexpected result (not a WP_User or WP_Error object) which is causing this issue.

    The plugin’s author should return “WP_Error object” in such cases to prevent this kind of situations, and Caleb’s suggestion is appreciated as well.

    Thanks.

    Tell the User Blocker folks this:

    Look at the very first line in their filter:

    $user = get_user_by('login', $username);

    get_user_by() can return ‘false’.

    Which first makes their next line of code
    $user_id = $user->ID;
    wrong, because they assume that they will always receive a WP-User and try to get a UserID from a boolean (not an Object).

    Second, it also makes their subsequent return value of ‘return $user;’ wrong, because that means they are passing an invalid value downstream to the next plugin, in this case WordFence.

    As @wfalaa stated, only WP_User or a WP_User_Error objects are valid. No booleans allowed.

    Hi @ymca,

    We have updated our “User blocker” plugin on wordpress.org with the solution that are suggested by other dev team.

    Many thanks to @crudhunter and @wfalaa for your hard efforts to find a solution with our plugin.

    Overall, with our great efforts we have provided a complete solution to client.

    Thanks again to all!

    @solwininfotech,

    Your plugin has been changed, yes. But not entirely for the better.

    Your new code now has multiple new problems.

    Putting a big

    if (!is_wp_error($user) && is_object($user)) {

    bracket around all your code and totally eliminating the get_user_by() (never actually translating the $username string) call might seem like a good idea, but not in reality.

    All that bracket does is to protect YOURSELF from getting into the situation WordFence was in. That someone upstream passes YOU values that are not what you think. But it adds new issues.

    Problem 1. The Authentication process starts by WordPress sending

    (null, $username, $userpassword)

    NULL.. As in, the first filter function will not have a WP_User at all as a parameter, but a ‘null’. The filter is responsible for filtering on $username/$userpassword and checking or looking up the username, when no $user structure has been found yet.
    Or in the case, that the $username is for example a banned/illegal name, a filter might not try to look up the $username at all, but will simply return WP_User_Error.

    A WP_User object is not found until the first filter translates the $username into a WP_User object. Then if the user and $userpassword is accepted by that particular filter, the filter passes a WP_User (rather than a WP_User_Error/WP_Error) as a return value.

    Given that you are bracketing your entire function, that simply means that if you are first to be called from wp_authenticate(), you become a pass-though. Doing nothing at all. You never look up or otherwise check the $username.

    This particular issue you are somewhat protected from, since WordPress initially inserts 3-4 internal ‘authenticate’ filters, which most likely would have translated $username before you ever get called. Why it might have appeared to work, when you tested it. But that is not an assumption that is really safe to make, since you are supposed to be able to handle NULL.

    Problem 2. You are now returning NULL.

    If there is a next filter in the chain AFTER you, like here WordFence, they might save the overall filter-result from your return value, because they are also responsible for accepting NULL as a first parameter. The next filter might then translate/validate/invalidate $username and return a correct value. But if you are alone or last in a filter-chain, you would be returning NULL to wp_authenticate() as the final filtering result..

    NULL is not a valid return value from any ‘authenticate’ filter. No more valid than the earlier value of ‘false’.

    wp_authenticate() in fact checks for NULL explicitly, and considers it a failure of the filter process that should not happen. It reacts by failing the whole login process, and declaring the login invalid.

    Hello @crudhunter,

    Can you please create a support ticket with our support portal ( http://support.solwininfotech.com/open.php ) and share one of your contact details? So, we can directly discuss with you regarding this issue and can resolve it for forever.

    Please mention this link in support ticket details as well. So, we can directly identify you.

    Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Getting a warning when trying to log.’ is closed to new replies.