Pings/Trackbacks: Auto-approve pingbacks from the same site - #12870
Pings/Trackbacks: Auto-approve pingbacks from the same site#12870youknowriad wants to merge 1 commit into
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
88555a2 to
e8a046f
Compare
Pingbacks carry no email address, so they never satisfy the `comment_previously_approved` option, which is enabled by default. Every pingback is held for moderation indefinitely as a result, including the ones a site sends to itself when a new post links to an older one. Approve a pingback whose source URL resolves to a published post on this site. A pingback is verified before it is stored: the source page is fetched, it must link to the target, and the comment is built from that page. Trackbacks are excluded, as their source, title, and excerpt are unverified request data. Existing moderation checks still take precedence, and the new `auto_approve_pingback` filter controls the decision. Props annezazu, avcascade, chriscct7, desrosj, dshanske, eurello, matt, mohkatz, SergeyBiryukov, stevegrunwell. Fixes #65016. See #24241. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
e8a046f to
5efe36f
Compare
Pingbacks carry no email address, so they can never satisfy the
comment_previously_approvedoption incheck_comment()— they always fall through toreturn false. That option is on by default, so every pingback is held for moderation indefinitely, including the ones a site sends to itself when a new post links to an older one. The only existing workaround is to disable the option, which also auto-approves pingbacks from every other site.Trac ticket: https://core.trac.wordpress.org/ticket/65016
Changes
check_comment()now approves a pingback whose source URL resolves to a published post on this site. No new function and no new setting.The decision is exposed as
auto_approve_pingback, defaulting to true for pingbacks from this site and false for all others:Two things worth checking in review:
url_to_postid(), which compares parsed hostnames, so a URL that merely contains the home URL is not treated as local.Why pingbacks only
An earlier revision of this PR also covered trackbacks. That was wrong, and it is worth stating why so the exclusion is not "fixed" later.
A pingback is verified before it is stored:
pingback_ping()fetches the source page, requires it to contain a link to the target, rejects source == target, and builds the comment from the fetched page. A trackback has none of that.wp-trackback.phptakes the source URL, title, excerpt, and blog name straight from$_POSTand never contacts the source.So trusting a trackback's claimed source means anyone can POST arbitrary content naming a local post and have it approved:
The trackback dedup is an exact string match on
comment_author_url, whileurl_to_postid()strips the fragment, so#x1,#x2, … all resolve to the same post and all pass.wp_check_comment_flood()throttles this to one per 15 seconds per IP, which is a rate limit rather than an authorization control. Verified locally: unauthenticated, approved on arrival, and held again once trackbacks were excluded. There is a regression test covering it.Testing
Verified end to end on a real site: publishing a post that links to an older one produces a pingback that lands approved, with an empty moderation queue. Adding
add_filter( 'auto_approve_pingback', '__return_false' )puts the same pingback back atcomment_approved = '0', and the forged trackback above is held.Three things unrelated to this patch get in the way of reproducing that in the standard Docker environment, in case anyone else hits them:
wp_should_disable_pings_for_environmentneeds filtering to false.wp_extract_urls()requires a literal.in the URL, so nothing is extracted with the defaultlocalhost:8889site URL. Using127.0.0.1:8889works.localhost:8889from inside the php container is that container. Requests need routing to the nginx service, keeping the originalHostheader so WordPress does not issue a canonical redirect.Pingbacks are dispatched from a
do_pingscron event, so a manualwp cron event run do_pingsavoids waiting for a subsequent request.Open question
The ticket asks whether this should be a setting or automatic; this is the automatic version. Related: #24241, where the opposite preference is argued, and which also asks for trackbacks — see above for why they are excluded.
On multi-author sites, any published post can trigger an auto-approved self-pingback. Restricting this to source posts whose author is the target's author or can
moderate_commentswould close that, reusing the trust rule already inwp_check_comment_data(). Left out for now — happy to add it if preferred over leaving it to the filter.Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5
Used for: Research, implementation, and tests; reviewed and edited by me.