Skip to content

Comments: Accept a stale nonce from the site's own page - #53532

Merged
arcangelini merged 7 commits into
trunkfrom
fix/comments-nonce-same-origin
Oct 13, 2026
Merged

arcangelini merged 7 commits into
trunkfrom
fix/comments-nonce-same-origin

Conversation

@arcangelini

@arcangelini arcangelini commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Proposed changes

  • A logged-in reader's comment needs our form nonce, which dies after 12 to 24 hours or when the login session it was made for ends (logging in again in another tab, a password change). Those readers get "Go back and try again", and going back restores the same dead nonce, so the retry fails too.
  • When the nonce fails, accept the post if its Origin is exactly this site's home or site origin: scheme, host and port. A forged cross-site post carries the other site's Origin, which is what the nonce guards against. A default port is ignored, as browsers leave it out; http://, another port, a sibling subdomain and null all still fail.
  • Checkpoint::is_same_site_request() now compares the full origin (scheme, host, port) instead of the host alone, and the nonce fallback uses it. A site stored as http:// but served over https still matches its https origin. Sign-in codes get the same tighter check.
  • Checkpoint::is_same_site_request() now refuses a request with no Origin, Referer or Sec-Fetch-Site at all. It used to let it through, which left sign-in codes open to a cross-site post from browsers that send none of them. Every browser that can run the sign-in flow sends Origin on the POST.
  • Drop the retry of a failed nonce as the logged-out user. The Origin check covers the case it handled, a logged-in reader served a page cached for nobody.
  • About 60 a week on Simple, all from real browsers that passed the same-site Origin filter, roughly 1 in 400 logged-in comments.
  • Core's own comment form has no nonce, so this is our extra layer; the Origin check keeps doing its job in every current browser.
  • A post with no Origin at all still needs a valid nonce.
  • The Origin fallback only applies to logged-in readers. A bot can send any Origin header, so it must never stand in for the nonce on a logged-out post (see Comments: Keep the form nonce out of the page HTML #53547).
  • Drops record_refusal( 'nonce' ): it recorded exactly the posts this now lets through.

Does this pull request change what data or activity we track or use?

jetpack_comments_comment_refused no longer fires with reason: nonce.

Testing instructions

  • Logged in, open a post using the new comment form.
  • In devtools, change the jetpack_comments_form_nonce hidden input's value to bad, then post. The comment posts.
  • Replay the same POST with curl and no Origin header (with your cookies). It's refused with "Sorry, this comment could not be posted."
  • Replay it with -H 'Origin: https://example.com', and again with the site's own host over http://. Both are refused.

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WoA dev site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin (Jetpack or WordPress.com Site Helper), and enable the fix/comments-nonce-same-origin branch.
  • To test on Simple, run the following command on your sandbox:
bin/jetpack-downloader test jetpack fix/comments-nonce-same-origin
bin/jetpack-downloader test jetpack-mu-wpcom-plugin fix/comments-nonce-same-origin

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


Follow this PR Review Process:

  1. Ensure all required checks appearing at the bottom of this PR are passing.
  2. Make sure to test your changes on all platforms that it applies to. You're responsible for the quality of the code you ship.
  3. You can use GitHub's Reviewers functionality to request a review.
  4. When it's reviewed and merged, you will be pinged in Slack to deploy the changes to WordPress.com simple once the build is done.

If you have questions about anything, reach out in #jetpack-developers for guidance!

@jp-launch-control

jp-launch-control Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Code Coverage Summary

This PR did not change code coverage!

That could be good or bad, depending on the situation. Everything covered before, and still is? Great! Nothing was covered before? Not so great. 🤷

Full summary · PHP report · JS report

@arcangelini
arcangelini merged commit bb1fb5f into trunk Oct 13, 2026
84 checks passed
@arcangelini
arcangelini deleted the fix/comments-nonce-same-origin branch October 13, 2026 15:48
@github-actions github-actions Bot added [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. and removed [Status] Needs Review This PR is ready for review. labels Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Comments [Status] UI Changes Add this to PRs that change the UI so documentation can be updated. [Type] Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant