Repository navigation
Tell logged-out users to log in again instead of posting an empty comment - #267
Merged
Merged
Conversation
…ment When a user's session expires (or they log out in another tab), the page still thinks they are logged in, so o2 sends `author` as the current user (`userLogin`, `userNicename`) to the nopriv write handler. create_comment() then read `author->name`, `email` and `url`, which aren't there, logged three undefined property warnings, and handed wp-comments-post.php an empty author, which rejects the comment with "please fill the required fields". Detect that case and fail with a "log in again" message the comment view shows. Default the remaining fields so hand-crafted messages (no `parentID`, no `author`, a non-object payload) are rejected by core or the type check instead of logging warnings. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Contributor
|
AI review · |
lancewillett
requested changes
Oct 15, 2026
lancewillett
left a comment
Contributor
There was a problem hiding this comment.
1 blocker, left a comment.
If the userLogin guard regressed, create_comment() would reach wp-comments-post.php, which exits on anything but POST. The test only failed loudly because the bootstrap's earlier output turns that branch's header() call into a warning. Make the request a POST so a regression always surfaces as a test failure. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
lancewillett
approved these changes
Oct 16, 2026
lancewillett
left a comment
Contributor
There was a problem hiding this comment.
Ran it locally: with the userLogin guard removed, the test now errors loudly, and you were right that the header warning already caught it before.
AI review · claude-opus-5-5
1 task
lancewillett
added a commit
that referenced
this pull request
Oct 16, 2026
A Docker MySQL recipe for bin/install-wp-tests.sh, verified from cold containers, and the testing patterns from #267: run tests that can reach wp-comments-post.php as POST, capture die_failure() output through wp_die_ajax_handler, and prove guard tests fail when the guard is removed. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed Changes
o2_NoPriv_Write_API::create_comment(), fail with alogged_outerror ("You have been logged out. Please log in again to comment.") when the message'sauthorcarries auserLogin.$_POSTremap intoget_comment_fields()and default missing fields.type, ininit().tests/phpunit/test-nopriv-write-api.php.When a user's session expires, or they log out in another tab, the page still thinks they're logged in. The comment view then sends
authoras the current user (userLogin,userNicename, …, seejs/views/comment.js:237) instead of the name/email/url form fields, and the request lands on the nopriv handler.create_comment()readauthor->name,emailandurl, logged a warning for each, and passed an empty author towp-comments-post.php, which rejects the comment with a generic "please fill the required fields" error. The comment view already showserrorText, so the user now sees why the comment failed.Seen in production on make.wordpress.org:
Hand-crafted requests such as
{"type":"comment","postID":999999999,"contentRaw":"test"}also loggedUndefined property: stdClass::$parentID(line 91) and more. These now get empty defaults and are rejected by core as before.A genuinely logged-out commenter is unaffected: that form sends
authoras{ name, email, url }with nouserLogin.Testing Instructions
master, the warnings above are logged and the comment fails with "please fill the required fields". On this branch, the "You have been logged out" error is shown.vendor/bin/phpunit --filter NoPrivWriteAPITestpasses. The tests fail withUndefined property: stdClass::$namewithout the fix.🤖 Generated with Claude Code