wp-background-processing icon indicating copy to clipboard operation
wp-background-processing copied to clipboard

Conflict when dispatching batch from Ajax call

Open koen12344 opened this issue 1 year ago • 4 comments

The library checks the nonce arg in the get_chain_id() function when calling dispatch(). That arg is potentially overwritten by plugins, causing the nonce validation to fail, and the request to 403. The process will then not be dispatched and no healthcheck will be scheduled.

koen12344 avatar Jan 11 '25 14:01 koen12344

Actually, diving deeper into the code, I think the issue is simply trying to dispatch a batch from any Ajax call. This will make the if ( empty( $this->chain_id ) && wp_doing_ajax() ) { line in get_chain_id() return true, and make it look for a nonce arg that isn't set, or doesn't apply to the library

koen12344 avatar Jan 11 '25 14:01 koen12344

Having this issue too. It's breaking the WooCommerce checkout since I'm using a queue to dispatch emails to a custom mail server.

Fix would be much appreciated.

craigrileyuk avatar Jan 29 '25 13:01 craigrileyuk

@craigrileyuk You can temporarily use my fixed branch by including the repo in your composer.json:

"repositories": [
    {
      "type": "vcs",
      "url": "https://github.com/koen12344/multisite-background-processing"
    }
  ],
"deliciousbrains/wp-background-processing": "dev-prod",

It fixes this issue, as well as the other issue I opened with processing batches on multisite. I use it in production on a few plugins

koen12344 avatar Jan 29 '25 14:01 koen12344

Thank you for finding this issue and providing the fix, I was really wondering what was happening suddenly, and the update of this library turned up to be the culprit.

remyperona avatar May 21 '25 13:05 remyperona