-
Notifications
You must be signed in to change notification settings - Fork 169
Fatal error when dispatching Async request with not valid cookies #107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@ianmjones sorry for bothering, just want to validate the issue and I'll create the PR. |
Hey @engahmeds3ed, thanks for the ping. While it seems like it would be best fixed in WordPress Core itself, that could take a while, and wouldn't make it's way to existing WordPress versions. If you have a nice simple fix, and can include unit tests, I'd definitely be open to reviewing it. |
Sure I can, will back to you once finishing that. |
@engahmeds3ed thank you for your suggested fix @engahmeds3ed @ianmjones what do you think of this updated version of original fix proposed by @engahmeds3ed:
|
Thanks @tdmkld I already started adding the idea of this code here and will create the pull request by tomorrow so cross fingers that this will fix it. |
Unfortunately because of this bug/feature in php core we can't change the numeric key to a string key, check this simple example here: https://onlinephp.io/c/7f6d6 I believe removing the integer keys will be the only solution here, I'll add a comment there in WP Core ticket, hope they fix it from their side. |
I did wonder how you were going to get around how PHP automatically casts a string that looks like an integer into an integer when used as an associative array key. The only real way around that is to prefix the integer "string" with a non-empty string value that makes it non-numeric, and remove the prefix later during analysis. I personally feel that the real solution here isn't so much to get WP's Cookie class to allow a numeric cookie name, but to simply not use a numeric as a cookie name. You're playing with fire if you ever use an array where the integer keys have significance anyway, it is very easy to use a function that resets the keys back to start from 0. To my mind, using a cookie name that is an integer without any identifiable source is just asking for trouble, cookie names are in a global namespace per domain/path. You can use a cookie name that is a real string unique to your plugin that holds an array with ID/Value/Sort values etc, or construct cookie names with a string prefix and trailing integer value, e.g. Probably best to hunt down whatever WordPress plugin is creating the cookies with integer names and politely ask the author to adjust their cookie names. |
Many thanks @ianmjones for this valuable discussion.
That'd be hard as cookies can be set with plugins/theme/js and I hope I can see the error in reality without applying this workaround. |
@ianmjones @engahmeds3ed thank you for these replies and valuable insights. Would the best course of action for us (the Wordpress website owners experiencing the 500's thrown by multiple plugins that bundle ActionScheduler) be to wait for the various plugin developers to address the issue on a per plugin basis and wait for new versions of these plugins to be released? Please advise. |
@tdmkld Waiting for those plugins to fix their code is not an option for me because we need to guard against that because if anyone with admin dashboard access can cause this error 500 with just creating a cookie with integer key in the browser. |
@engahmeds3ed thank you for that advice, is there any danger in using the snippet to remove these integer key cookies? I'm hesitant to remove them because I don't know why or how they are being generated in the first place, are they serving a purpose? |
Steps to reproduce:
admin_init
Root cause:
This is happening because we pass the cookies without any sanitization/validation here:
https://github.com/deliciousbrains/wp-background-processing/blob/master/classes/wp-async-request.php#L145
I can create a pull request for that change once u check and validate the bug itself.
Related to woocommerce/action-scheduler#985
The text was updated successfully, but these errors were encountered: