Jetpack Comments: Different user ids in the environment when creating and verifying the nonce
Impacted plugin
Jetpack
Quick summary
In #23439 we added nonces to the comments system, which are not being verified properly, If you're signed in to the site.
The nonce is generated with the idea of the user visiting the site, but the validation happens under id: 0 (anonymous) wp_verify_nonce fails.
https://github.com/Automattic/jetpack/assets/746152/7944b4f0-e9b0-4a00-aef1-75d1adffd689
Steps to reproduce
- Activate Jetpack comments under Jetpack -> Settings -> Discussion
- On a post, while signed in to the site, try to leave a comment
- Expect to get a
Nonce verification failedmessage.
A clear and concise description of what you expected to happen.
I expected to be able to write a comment being signed in.
What actually happened
I can't write a comment
Impact
Some (< 50%)
Available workarounds?
No and the platform is unusable
Platform (Simple and/or Atomic)
No response
Logs or notes
No response
π SCRUBBING : RESULT - Replicated / Could Not Replicate / Uncertain
- Tested on Simple β Could Not Replicate
- Tested on Atomic β Could Not Replicate
- Tested on Self-Hosted site with Jetpack Connected - Could Not Replicate
π FINDINGS/SCREENSHOTS/VIDEO
- I was unable to replicate the issue on any test sites. On my self-hosted site, I tested commenting with both the owner/admin of the site, and an Editor, and both could comment as expected.
Screenshots/Recordings
https://github.com/Automattic/jetpack/assets/27249804/b34ac006-6a96-4dc4-8648-f5f82560b357
π ACTIONS
- Requested author feedback
π Message to Author
- @oskosk are there more detailed steps to replicate this problem that you can share?
@cuemarie Have you tried with this setup?
- Logged in to .com
- Logged in to the site with a user whose Jetpack connection matches the .com account you're signed with to .com
- Commenting
For example. This is in an incognito window. on a Jurassic Ninja site.
-
If I'm signed into the self-hosted site, but not to WordPress.com, I can comment.
-
In the same incognito window, I sign in to .com with the user that connected the Jetpack site and I can't comment
The diagnosis here, matches mine
Upon further digging, the nonce is different because wp_get_current_user fails upon submission, and returns 0 as the user_id when it is typically something else at page load (in my case, 2). Iβm not sure why the wp_get_current_user fails upon submission. Hopefully, the developers can figure it out. Fort posterity, I checked this not only with my theme but also twenty-twenty-two. Both produced the same error for the same reasons.
https://wordpress.org/support/topic/jetpack-comment-error-nonce-verification-failed/#post-16276738
Thanks @oskosk for the added details! It seems the issue was my Discussion Settings. Updated notes below:
π SCRUBBING : RESULT - Replicated / Could Not Replicate / Uncertain
- Tested on Simple β Could Not Replicate
- Tested on Atomic β Replicated
- Replicable outside of Dotcom β Yes
π FINDINGS/SCREENSHOTS/VIDEO
-
I was able to repro on Atomic and self-hosted site with the following steps:
-
Settings > Discussion, enable
Users must be registered and logged in to comment -
Refreshed post, and clicked "log in" under comment thread
-
Log in to the WordPress.com account that the site is connected to via Jetpack
-
Leave a comment.
Screenshots/Recordings
Atomic
https://github.com/Automattic/jetpack/assets/27249804/ada06f27-b1fc-4e72-a641-2619b4fa3d45
Self-Hosted
https://github.com/Automattic/jetpack/assets/27249804/46a8798e-0f59-49de-8f5a-baa85e7431b4
Simple site did not reproduce the same error, and commenting worked as expected.
π ACTIONS
- Assigned to Other
πJust a heads up FYI to @Automattic/loop as this impacts commenting/engagement.
Thanks @cuemarie.
Noting here that in the Jetpack Admin page settings we don't have that setting as it comes from core. In calypso both sets of settings are merged
Jetpack -> Settings -> Discussion
Settings -> Discussion
Calypso
Related:
- p1690992899536269-slack-CA17PSW87
- 7666-gh-jpop-issues
I looked into this a bit. I was able to reproduce on one site (a brand new JN site, freshly connected to my a11n acount), but not on others. I was not able to figure out what was different about the site where I could reproduce.
A few things to note:
- You do not need to enable the user login requirement (as shown on the screenshots above) to be able to reproduce the issue.
- You do need to be logged in with both the local admin account and the linked WordPress.com user.
- When the problem happens, there is indeed no user info available when Jetpack's
pre_comment_on_postruns, so the nonce check logically fails.
The Verbum comment UI is slowly getting activated for more and more folks, and it does complicate testing in some scenarios since it does not always seem to reflect the current user situation on the site. In the example below, I was logged in as an admin on the site:
In this scenario, I should be logged in in the comment form as well. I cannot seem to be able comment as a logged in user at the moment.
In fact, one could argue that when you are locally logged in as admin, you may not need any type of Jetpack Comment UI; you are already logged in, you do not need any kind of social login option at this point. Looking at the codebase, it looks like logged in users should be allowed to post with other options so the codebase disagrees with my statement above: https://github.com/Automattic/jetpack/blob/24b4c87ebc8e497f57c524e72ff0d50d8c576327/projects/plugins/jetpack/modules/comments/base.php#L218-L227
If we removed the Jetpack Comment UI when you're logged in, it would solve this issue. I think it may also avoid some confusion around Jetpack Comments and social login. It would, however, change the way Jetpack Comments have worked until today, and may potentially cause more confusion.
At this point, I'm not sure how to move forward with this. @Automattic/vertex Since you've been working on Verbum, you're most likely the most familiar with this at the moment. Do you have any ideas?
I looked into this a bit. I was able to reproduce on one site (a brand new JN site, freshly connected to my a11n acount), but not on others. I was not able to figure out what was different about the site where I could reproduce.
A few things to note:
- You do not need to enable the user login requirement (as shown on the screenshots above) to be able to reproduce the issue.
- You do need to be logged in with both the local admin account and the linked WordPress.com user.
- When the problem happens, there is indeed no user info available when Jetpack's
pre_comment_on_postruns, so the nonce check logically fails.The Verbum comment UI is slowly getting activated for more and more folks, and it does complicate testing in some scenarios since it does not always seem to reflect the current user situation on the site. In the example below, I was logged in as an admin on the site:
In this scenario, I should be logged in in the comment form as well. I cannot seem to be able comment as a logged in user at the moment.
In fact, one could argue that when you are locally logged in as admin, you may not need any type of Jetpack Comment UI; you are already logged in, you do not need any kind of social login option at this point. Looking at the codebase, it looks like logged in users should be allowed to post with other options so the codebase disagrees with my statement above:
https://github.com/Automattic/jetpack/blob/24b4c87ebc8e497f57c524e72ff0d50d8c576327/projects/plugins/jetpack/modules/comments/base.php#L218-L227
If we removed the Jetpack Comment UI when you're logged in, it would solve this issue. I think it may also avoid some confusion around Jetpack Comments and social login. It would, however, change the way Jetpack Comments have worked until today, and may potentially cause more confusion.
At this point, I'm not sure how to move forward with this. @Automattic/vertex Since you've been working on Verbum, you're most likely the most familiar with this at the moment. Do you have any ideas?
Our efforts are scattered across multiple places ATM, but we have this patch D123363-code. We need to address the issues there.
We were fixing a related issue and to me it seems that this got fixed as well. Can someone try to reproduce this? No need for any testing setup except a sandbox pull.
@heavyweight This is still happening I'm afraid.
https://github.com/Automattic/jetpack/assets/7000684/3a20b10b-1881-4615-9e88-9db68a51bcdb
Not sure what I'm doing wrong. I logged in to the site with email password. The same email from my wp account. Later I logged in into wordpress.com. When posting the comment I don't see the error.
I was having trouble reproducing as well; it happens on some of my sites, but not others. I haven't been able to understand why sometimes it works and sometimes it doesn't.
A few users affected by this:
8481771-zen 8495110-zen
https://wordpress.org/support/topic/chrome-jetpack-gives-nonce-errors-firefox-jetpack-is-completely-fine/
Support References
This comment is automatically generated. Please do not edit it.
- [ ] 8481771-zen
- [ ] 8495110-zen
- [ ] 8669002-zen
Another user reporting it on this forum thread: https://wordpress.org/support/topic/chrome-jetpack-gives-nonce-errors-firefox-jetpack-is-completely-fine/#post-17920955
The PR got merged https://github.com/Automattic/jetpack/pull/38554 It will be fixed once jetpack is deployed to atomic sites
@heavyweight - is there any chance that this could still be a problem? I'll refrain from reopening this, but we have a Jetpack user in 8669002-zen reporting this problem, and we're able to reproduce the Nonce verification failed. error when trying a test comment on their site.
After the merged PR I didn't expect to see this again. I tried to reproduce on my atomic site and couldn't. I tried on the customer site and the comment went through.
I suspect that this could be an old or cached nonce that got sent. I see on the ticket that @lschuyler managed to reproduce this. Could you share replication steps?
I simply loaded the site and attempted to leave a comment on the latest post and got the Nonce verification failed. message. I then checked the Jetpack connection, and saw a bit of a sync discrepancy in the Sync Validation. I clicked the Schedule a Fix button. I came back later in the hour to confirm that was fixed. I did a hard refresh of the blog and attempted to comment again, but got the same Nonce verification failed. when I tried. I checked the comments page on her dashboard just to see if the comment went through anyway, but it did not. Hope that helps!
In this scenario, I should be logged in in the comment form as well. I cannot seem to be able comment as a logged in user at the moment.