jetpack icon indicating copy to clipboard operation
jetpack copied to clipboard

Jetpack Comments: Different user ids in the environment when creating and verifying the nonce

Open oskosk opened this issue 3 years ago β€’ 31 comments

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

  1. Activate Jetpack comments under Jetpack -> Settings -> Discussion
  2. On a post, while signed in to the site, try to leave a comment
  3. Expect to get a Nonce verification failed message.

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

oskosk avatar Aug 17 '23 14:08 oskosk

πŸ“Œ 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 avatar Aug 17 '23 16:08 cuemarie

@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. image

  • In the same incognito window, I sign in to .com with the user that connected the Jetpack site and I can't comment

image

oskosk avatar Aug 17 '23 18:08 oskosk

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

oskosk avatar Aug 17 '23 19:08 oskosk

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 Markup on 2023-08-17 at 13:53:09

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

cuemarie avatar Aug 17 '23 20:08 cuemarie

πŸ””Just a heads up FYI to @Automattic/loop as this impacts commenting/engagement.

cuemarie avatar Aug 17 '23 21:08 cuemarie

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

image

Settings -> Discussion

image

Calypso

image

oskosk avatar Aug 17 '23 21:08 oskosk

Related:

  • p1690992899536269-slack-CA17PSW87
  • 7666-gh-jpop-issues

jeherve avatar Sep 13 '23 07:09 jeherve

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:

  1. You do not need to enable the user login requirement (as shown on the screenshots above) to be able to reproduce the issue.
  2. You do need to be logged in with both the local admin account and the linked WordPress.com user.
  3. When the problem happens, there is indeed no user info available when Jetpack's pre_comment_on_post runs, 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:

image

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?

jeherve avatar Oct 03 '23 11:10 jeherve

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:

  1. You do not need to enable the user login requirement (as shown on the screenshots above) to be able to reproduce the issue.
  2. You do need to be logged in with both the local admin account and the linked WordPress.com user.
  3. When the problem happens, there is indeed no user info available when Jetpack's pre_comment_on_post runs, 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:

image 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.

heavyweight avatar Oct 04 '23 18:10 heavyweight

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 avatar Oct 06 '23 08:10 heavyweight

@heavyweight This is still happening I'm afraid.

jeherve avatar Oct 06 '23 15:10 jeherve

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.

heavyweight avatar Oct 06 '23 15:10 heavyweight

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.

jeherve avatar Oct 06 '23 16:10 jeherve

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/

danjjohnson avatar Jul 20 '24 10:07 danjjohnson

Support References

This comment is automatically generated. Please do not edit it.

  • [ ] 8481771-zen
  • [ ] 8495110-zen
  • [ ] 8669002-zen

github-actions[bot] avatar Jul 20 '24 10:07 github-actions[bot]

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

StefMattana avatar Jul 30 '24 08:07 StefMattana

The PR got merged https://github.com/Automattic/jetpack/pull/38554 It will be fixed once jetpack is deployed to atomic sites

heavyweight avatar Jul 30 '24 08:07 heavyweight

@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.

jenhooks avatar Sep 01 '24 14:09 jenhooks

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.

Screenshot 2024-09-02 at 14 18 54

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?

heavyweight avatar Sep 02 '24 12:09 heavyweight

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!

lschuyler avatar Sep 03 '24 15:09 lschuyler