-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Update UID only for WooCommerce cookies #29542
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
Conversation
roykho
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested fine with the steps outlined in the PR. I also further tested Bookings Availability to make sure the REST API is working there.
Left some comments for improvement.
| $customer_id = (string) get_current_user_id(); | ||
| } | ||
|
|
||
| return $customer_id; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return type is stated as string and only line 203 enforces that even though 201 may already be string. So perhaps remove (string) from line 203 and put it on line 206 return (string) $customer_id would be better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only get_current_user_id() returns int, that's why I didn't want to cast string for everything by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See generate_customer_id() it returns always string, even when we need to use get_current_user_id() we cast string too.
roykho
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
All Submissions:
Changes proposed in this Pull Request:
We need to filter into
nonce_user_logged_outto prevent CSRF attacks for unregistered users, but we introduced some issues since changing this nonce will also invalidate all cookies because it relies in the customer UID.This PR proposes to only change WooCommerce's cookies, so it doesn't affect 3rd party integrations, unless they are incorrectly using
woocommerceas a prefix for any cookie or nonce.Closes #23682.
How to test the changes in this Pull Request:
I created a plugin to help test how nonces behave: https://gist.github.com/claudiosanches/71e4a1282599509720d72927d10a94ee
But you can also test and follow the same steps in #28364 to test with " WordPress Popular Posts".
/wp-admin/admin.php?page=wc-settings&tab=productsand "Enable AJAX add to cart buttons on archives".Test Requestit will displaytruein the bottom of the widget because a of successful request.Test Requestbutton.Test Requestagain, you'll see now an authentication error from the REST API, go to any page and check thatTest Requestreturns the same error every time now.Test Requestworks as expected and always returns true, even after completing a checkout.Other information:
Changelog entry