ajax - Why does Wordpress Heartbeat login not refresh the nonces?

admin2025-01-08  3

Here's an interesting experiment: Go to wordpress plugins listing page, notice the activate, deactivate links all have a nonce part in the request.

In a second tab, log out of the site, and go back to plugin listing page.

After awhile, the page realizes it's not logged in, and pops up a log in screen. Log in, and click an "activate" or "deactivate" button.

Notice it gives the nonce-failure message, "are you sure you want to do this"? Because the previous session's nonces don't work. Why does Wordpress not know to refresh these nonces? I thought new nonces would be sent back as a heartbeat-ajax, but it looks like there isn't an ajax request with the login screen.

Update: It seems this is called when the user logs in, but I guess not too many scripts are smart about acting on this trigger?

$( document ).on( 'heartbeat-tick.wp-auth-check', function( e, data ) {
        if ( 'wp-auth-check' in data ) {
            schedule();
            if ( ! data['wp-auth-check'] && wrap.hasClass('hidden') ) {
                show();
            } else if ( data['wp-auth-check'] && ! wrap.hasClass('hidden') ) {
                hide();
            }
        }
    }).

Here's an interesting experiment: Go to wordpress plugins listing page, notice the activate, deactivate links all have a nonce part in the request.

In a second tab, log out of the site, and go back to plugin listing page.

After awhile, the page realizes it's not logged in, and pops up a log in screen. Log in, and click an "activate" or "deactivate" button.

Notice it gives the nonce-failure message, "are you sure you want to do this"? Because the previous session's nonces don't work. Why does Wordpress not know to refresh these nonces? I thought new nonces would be sent back as a heartbeat-ajax, but it looks like there isn't an ajax request with the login screen.

Update: It seems this is called when the user logs in, but I guess not too many scripts are smart about acting on this trigger?

$( document ).on( 'heartbeat-tick.wp-auth-check', function( e, data ) {
        if ( 'wp-auth-check' in data ) {
            schedule();
            if ( ! data['wp-auth-check'] && wrap.hasClass('hidden') ) {
                show();
            } else if ( data['wp-auth-check'] && ! wrap.hasClass('hidden') ) {
                hide();
            }
        }
    }).
Share Improve this question edited Aug 22, 2014 at 6:57 NoBugs asked Jul 29, 2014 at 1:27 NoBugsNoBugs 4526 silver badges22 bronze badges 1
  • Related bug: core.trac.wordpress.org/ticket/29312 – NoBugs Commented Mar 6, 2015 at 7:43
Add a comment  | 

1 Answer 1

Reset to default 2

because the Heartbeat system is mostly orthogonal to the rest of wordpress and therefor it is not really aware what is the content of the pages it runs on. As it is a relatively new system it probably has edges that are not well defined or tested, and if you think there is some weird behaviour or an actual bug please open a ticket at the wordpress trac - https://core.trac.wordpress.org/

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736270549a1437.html

最新回复(0)