Repository navigation
Prevent flagging of hidden comments such as order notes - #25
Merged
Merged
Conversation
The public flag_comment AJAX handler checked only that comment_id was numeric and carried the global report nonce. That nonce is shared by every anonymous visitor and is not bound to a comment, so any numeric ID could be reported, including records that merely share the comments table such as WooCommerce order notes. Once the threshold was reached these hidden entries were moved to moderation even though no report link was ever rendered for them. Gate flagging on a new is_reportable_comment() helper so only existing, ordinary comment types are actionable, and expose filters to adjust the reportable types or veto a target. Add a regression test covering order notes, pingbacks, trackbacks, missing comments and the filters.
GaryJones
force-pushed
the
GaryJones/pr-validation-fix
branch
from
August 19, 2026 00:17
859ad36 to
f4449ec
Compare
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.
Summary
Safe Report Comments lets visitors flag a comment as inappropriate, and once a configurable number of reports is reached the comment is moved to moderation. The public AJAX handler behind this,
flag_comment(), validated only that the submittedcomment_idwas numeric and that the request carried the plugin's report nonce. That nonce is a single global value, shared by every anonymous visitor and not tied to any particular comment, so it proves only that the caller loaded a page with a report link, not that the target was ever meant to be reportable.WordPress stores more than blog comments in the comments table. WooCommerce, for instance, keeps internal order notes there with a
comment_typeoforder_note. Because nothing checked the target's type, an anonymous visitor could lift the global nonce from any public post and submit reports against arbitrary comment IDs, including hidden records that never had a report link rendered. On reaching the threshold the plugin calledwp_set_comment_status( $comment_id, 'hold' )on them, changing their approval state and firing the moderation hooks, with no authorisation for that specific target. This was raised in an external security report, with WooCommerce order notes as the demonstrated case.The fix adds an
is_reportable_comment()guard thatflag_comment()now consults before any report metadata is written or status changed. It confirms the comment exists and is an ordinary public comment type (an empty type orcomment), rejecting order notes, pingbacks, trackbacks and other subtypes that merely share the table. Two filters keep it extensible:safe_report_comments_reportable_comment_typesto adjust the accepted types andsafe_report_comments_is_reportable_commentto veto or allow a specific target. Rejected requests reuse the existing invalid-values response, so client behaviour for a bad request is unchanged. Extracting the check into its own method also makes it directly testable, and the newtests/test-reportable-comment.phplocks in the behaviour for ordinary comments, order notes, pingbacks, trackbacks, a missing comment and both filters.The change is deliberately narrow: it gates the target by type only. Verifying parent-post visibility (comments on private or password-protected posts) was noted in the report as a lesser, separate concern, and the
safe_report_comments_is_reportable_commentfilter is the intended extension point should we choose to add it. One claim in the report, that a held order note vanishes fromwc_get_order_notes(), looked doubtful becauseWP_Comment_Queryreturns both approved and held comments by default; this PR closes the underlying authorisation gap regardless, since acting on a non-reportable target is wrong on its own.Test plan
order_notecomment ID viaadmin-ajax.phpreturns the invalid-values message and leaves the note untouched, while an ordinary comment still reaches moderation at the threshold.