Close the comment read paths that bypass comments_pre_query - #48
Open
jeremyfelt wants to merge 2 commits into
Open
Close the comment read paths that bypass comments_pre_query#48jeremyfelt wants to merge 2 commits into
jeremyfelt wants to merge 2 commits into
Conversation
WP_Query loads comment feeds with its own SQL instead of WP_Comment_Query, so the comments_pre_query filter never sees them and historical comments were served in full at /?feed=comments-rss2, /comments/feed/, and any per-post /<post>/feed/ URL. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017SdvjbC3xVfdC4jVZNrChL
WP_REST_Comments_Controller loads a single comment with get_comment(), which bypasses WP_Comment_Query, so /wp/v2/comments/<id> served approved comments in full even though the collection endpoint returned an empty array. Dropping the routes closes the read and write endpoints together. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017SdvjbC3xVfdC4jVZNrChL
Plugin Check: 1 error(s), 0 warning(s)
|
jeremyfelt
force-pushed
the
fix/close-comment-read-paths
branch
from
August 21, 2026 17:56
4322262 to
5017e92
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.
filter_comments_pre_query()only coversWP_Comment_Query. Comment feeds and the REST API each read comments another way, so historical approved comments were still served in full on a site running this plugin.Reproduced on
wp-env(WordPress 7.0, plugin active, one approved comment on post 1) before and after:/wp-json/wp/v2/comments/3/wp-json/wp/v2/comments[]POST /wp-json/wp/v2/comments/?feed=comments-rss2/?feed=comments-atom/comments/feed//hello-world/feed//hello-world/feed/atom//?p=1&feed=rss2&withcomments=1/feed/,/feed/atom//,/hello-world/,/?s=hello,/wp-sitemap.xml/wp-json/,/wp-json/wp/v2/posts,/wp-json/wp/v2/posts/1The "after" run was done with the site's cached
rewrite_rulesstill holding all nine comment rules, includingcomments/feed. Nothing here depends on the rewrite rules being regenerated.Changes
Block comment feed requests with a 410 response.
WP_Querybuilds comment feeds with its own SQL (class-wp-query.php:2815for archives,:3475for singular), socomments_pre_querynever runs.is_comment_feed()ontemplate_redirectcatches every variant, including the query-string form and per-post feeds. 410 rather than 404 tells feed readers the resource is permanently gone;wp_die()returns an XML error body when the request asks for XML.Remove the core comment routes from the REST API.
WP_REST_Comments_Controllerresolves a single comment withget_comment(), which never runs aWP_Comment_Query. Filteringrest_endpointsdrops/wp/v2/commentsand/wp/v2/comments/<id>, which also takes them out of the/wp-json/index and closes the write endpoints. Only thewp/v2namespace is touched.Checks
composer phpcsandcomposer phpstan(level 9) both clean. No PHP notices indebug.log.Not included
comments_rewrite_rulesfilter only affects rules as they are generated, so a site keeps whatever is cached inrewrite_rulesuntil someone re-saves the permalink settings. Left alone deliberately: those stale rules resolve to comment feeds that now return 410 regardless, so the only thing flushing buys is a tidier rule table, at the cost of activation/deactivation hooks this plugin does not otherwise need.readme.txt/README.mddescription bullets and the changelog. This repo adds those in the release commit, not in fix commits.replieslink in post REST responses. Core hard-codes it forpostandpageregardless of comment support (class-wp-rest-posts-controller.php:2258), so?_embednow returns arest_no_routeerror object there instead of comment data. No leak, just a dangling link.wp.getComment, which also callsget_comment()directly. It requires an authenticated user withmoderate_comments, so it is not part of the public exposure this fixes.🤖 Generated with Claude Code
https://claude.ai/code/session_017SdvjbC3xVfdC4jVZNrChL