Repository navigation
Abilities: Only register the plugin's copies of core abilities when WordPress core does not provide them - #1251
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1251 +/- ##
==========================================
Coverage 85.14% 85.14%
Complexity 4825 4825
==========================================
Files 189 189
Lines 17910 17910
==========================================
Hits 15249 15249
Misses 2661 2661
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
saarnilauri
left a comment
There was a problem hiding this comment.
Thanks for working on this.
First a small change:
Content.phpis missing the "last synced" docblock line
The PR description says "The class docblocks state the core revision each class was last synced from: Content r64907, Users r65002, Settings r64346." The diff only adds that line to Settings.php and Users.php:
Please, add it to the Content class docblock.
Second item is more complex.
- The plugin's
Contentcopy is behind core r65045, which is security-relevant (follow-up, or fix here)
Core r65045 (2026-10-30, "Restrict content-query author visibility to viewable post types") changed get_visible_author() to count only publicly viewable post types:
// core trunk
$post_types = array_values( array_filter( get_post_types( array( 'show_in_abilities' => true ), 'names' ), 'is_post_type_viewable' ) );The plugin still has the old line (includes/Abilities/Content/Content.php:1448):
$post_types = get_post_types( array( 'show_in_abilities' => true ), 'names' );Without the filter, a published post in a show_in_abilities but non-viewable post type makes that author's slug visible to any logged-in user, which is an author-enumeration side channel. After this PR, 7.2+ sites get core's fixed version. Sites on 7.0/7.1 keep the plugin copy, so the gap stays there.
This is exactly the kind of drift #1240 is about, so I'd either:
- port r65045 in this PR (one line plus the docblock wording, with core's
test_author_slug_is_not_exposed_by_posts_in_a_non_viewable_post_typetest), and record the sync as r65045; or - open a follow-up issue and link it here, keeping the docblock at r64907 so the gap is visible.
@gziolo @dkotter What do you think? Should this PR complete the sync or add a followup for it?
What?
Closes #1240. Follow up to #1206, #1207 and #1208.
The plugin's copies of
core/settings-get,core/users-queryandcore/content-querynow stand down when the ability is already registered, instead of unregistering the core ability and replacing it.Why?
WordPress 7.2 registers these three abilities natively. Until now, each plugin class unregistered the core copy and registered its own on
wp_abilities_api_initpriority 11, regardless of the WordPress version. On 7.2+ that means:This was raised in the security audit of the three PRs and confirmed in #1208 (comment).
How?
Settings.php,Users.php,Content.php: whenwp_has_ability()reports the ability is registered,register()returns instead of callingwp_unregister_ability(). InSettings::register()the check moves to the top, so the plugin does not repeat the initial settings registration that core already did.required_capabilitiesis not supported before WordPress 7.2; a// Plugin:comment marks this.test_override_replaces_existing_core_*are renamed totest_keeps_existing_core_*and assert that the core-provided ability is kept.test_registers_plugin_copy_when_core_has_nonetests cover the path for WordPress before 7.2.SettingsTest,Content_RestTestandUsers_RestTestremove any core-provided copy insetUp(), so on WordPress trunk they keep testing the plugin's copy rather than core's.On the points left open in the issue:
wp_has_ability()alone. It is the simplest option, needs no version table, and also stands down for a third-party polyfill.wpai_override_core_abilitiesfilter is added. Unit tests remove the core copy directly, and manual testing of the plugin's copy works on WordPress below 7.2. A filter is public API that is easy to add later but hard to remove, so it can be a follow-up if it turns out to be needed.Note: on WordPress trunk,
UsersTest::test_string_input_from_direct_calls_is_normalizedfails withinput[where][ids] has duplicate items. That test removes the core copy itself and runs the same code asdevelop, so the failure is not caused by this change. It comes from stricter input validation in trunk.Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Implementing the change and tests, looking up the core sync revisions, and running the checks on WordPress 7.1 and trunk; final implementation and tests were reviewed by me.
Screenshots or screencast
Not applicable: no UI changes.
Changelog Entry