• Resolved Micha

    (@michaing)


    I recently face TypeError’s with the plugin, when a login is blocked as brute force attempt and tried to be logged, it seems. I suspect this being the case since I upgraded to PHP8.1, though it seems to be a bug in the code independently:

    
    Error message: Uncaught TypeError: json_decode(): Argument #1 ($json) must be of type string, array given in /var/www/blog/wp-content/plugins/wordfence/lib/wfConfig.php:545
    Stack trace:
    #0 /var/www/blog/wp-content/plugins/wordfence/lib/wfConfig.php(545): json_decode()
    #1 /var/www/blog/wp-content/plugins/wordfence/lib/wfUtils.php(1730): wfConfig::getJSON()
    #2 /var/www/blog/wp-content/plugins/wordfence/lib/wfUtils.php(1615): wfUtils::check_and_log_last_error()
    #3 /var/www/blog/wp-content/plugins/wordfence/lib/wfActivityReport.php(448): wfUtils::IP2Country()
    #4 /var/www/blog/wp-content/plugins/wordfence/lib/wordfenceClass.php(3108): wfActivityReport::logBlockedIP()
    #5 /var/www/blog/wp-content/plugins/wordfence/lib/wordfenceClass.php(3126): wordfence::checkSecurityNetwork()
    #6 /var/www/blog/wp-content/plugins/wordfence/lib/wordfenceClass.php(3098): wordfence::processBruteForceAttempt()
    #7 /var/www/blog/wp-includes/class-wp-hook.php(303): wordfence::authenticateFilter()
    #8 /var/www/blog/wp-includes/plugin.php(189): WP_Hook->apply_filters()
    #9 /var/www/blog/wp-includes/pluggable.php(593): apply_filters()
    #10 /var/www/blog/wp-includes/user.php(95): wp_authenticate()
    #11 /var/www/blog/wp-login.php(1142): wp_signon()
    #12 {main}
    

    In lib/wfConfig.php(545), the declared function is:

    
    getJSON($key, $default = false, $allowCached = true)
    

    It hence expects up to three arguments, the second being an optional default JSON to return. In lib/wfUtils.php(1730) however it is called like this:

    
    wfConfig::getJSON($previousKey, array(0, false));
    

    Hence as second argument is an array and no JSON, which then causes the type error in json_decode. Based on other getJSON calls in the code, it is intended that the second argument is/can be an array, and if json_decode returns null, it is also returned directly, where a decoded array is expected. But the same cannot be used as input to json_decode, or course. In the get function where the JSON string is derived, I changed:

    
    return $default
    

    to

    
    return @json_encode($default);
    

    as a quick and dirty solution so that the default is passed as JSON string into json_decode, but as array when json_decode returns null. This back and forth however doesn’t look nice and probably it makes more sense to change the get function to return null instead of $default so that the input array is always returned directly without back and forth decoding/encoding:

    
                    if (!self::$tableExists) {
                            return null;
                    }
    
                    $table = self::table();
                    if (!($option = $wpdb->get_row($wpdb->prepare("SELECT name, val, autoload FROM {$table} WHERE name = %s", $key)))) {
                            return null;
                    }
    

    Best regards,

    Micha

    • This topic was modified 4 years, 4 months ago by Micha. Reason: Found further info about how getJSON is intended to be used
    • This topic was modified 4 years, 4 months ago by Micha.
    • This topic was modified 4 years, 4 months ago by Micha.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter Micha

    (@michaing)

    Subsequent edits of a topic trigger an automatic mark as spam? Please tune this algorithm…

    Plugin Support wfpeter

    (@wfpeter)

    Hi @michaing, thanks for your detailed message.

    We at Wordfence don’t maintain the WordPress forums to rectify any reasons why a message may have been flagged as spam. I expect the WordPress.org moderators have already reviewed this topic and correctly decided that it isn’t.

    PHP 8.1 is not officially released until November 25th 2021 so we wouldn’t recommend running it on a production site for at least a few months. WordPress core still has some outstanding issues on PHP 8.1 as well, so you could encounter problems in another area of your site too. There will be a compatibility release of Wordfence, including a fix for the issue you’ve spotted here, coming up shortly although we can’t commit to exact dates or timescales here on the forum.

    Thanks,

    Peter.

    Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    Moderator note:

    We find that Akismet generally flags rapid edits as potential spam, so humans need to review:

    This topic was modified 3 days, 7 hours ago by Micha. Reason: Found further info about how getJSON is intended to be used
    This topic was modified 3 days, 7 hours ago by Micha.
    This topic was modified 3 days, 7 hours ago by Micha.
    Thread Starter Micha

    (@michaing)

    I’ll review more carefully before posting next time. Sorry for the extra moderation work.

    Also WordPress itself does not officially support PHP8.1 but is working on it for WordPress v5.9. But as it doesn’t hurt to have PHP8.1 related issues collected or even resolved before its official release, I didn’t hesitate to report it. If there is a better place to do so, instead of a ticket here, please redirect me.

    Best regards,

    Micha

    Plugin Support wfpeter

    (@wfpeter)

    Hi @michaing,

    We certainly appreciate feedback from the community to help resolve issues especially when we’re working on a compatibility release such as this. Your observervation is totally correct and is on our list of fixes to make. I just wanted to be thorough with my response regarding PHP 8.1 as others will often reference tickets on the forums.

    You can always address issues like this and product suggestions directly to feedback @ wordfence . com so can be seen immediately by the correct team.

    Thanks,

    Peter.

    Thread Starter Micha

    (@michaing)

    Great. I’ll send an email then, when facing PHP8.1 related issues, until it is supported officially by WordPress and by Wordfence. Makes sense to not spam a support/bug tracker with unsupported setup/beta testing.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘TypeError: json_decode() in lib/wfConfig.php(545)’ is closed to new replies.