Compare user identities strictly - #767
Closed
obenland wants to merge 1 commit into
Closed
Conversation
Several checks matched a user login or nicename against a list using a loose comparison. PHP compares two numeric strings numerically rather than character by character, so logins that are different strings but equal numbers matched each other. Pass the strict flag to `in_array()` and use `===` in the equivalent scalar comparisons, so identities only match on an exact string. Both operands are strings in every case: the lists come from `get_col()` and the needles from `WP_User`. The contributor check in `Capabilities::map_meta_cap()` already did this; this brings the surrounding checks in line. Adds coverage for the committer check, including the author fallback used when a published plugin has no committer rows. Co-Authored-By: Claude Opus 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.
A number of places matched a user login or nicename against a list of them using a loose comparison. PHP compares two numeric strings numerically rather than character by character, so two logins that are different strings but equal numbers compared as the same user.
This passes the strict flag to
in_array()and uses===in the equivalent scalar comparisons, so an identity only matches on an exact string.Both operands are strings everywhere this applies — the lists come from
$wpdb->get_col(), and the needles fromWP_User— so nothing that matched before stops matching.Changed
plugin-directory/class-capabilities.php— committer checkplugin-directory/api/routes/class-plugin-committers.php— last-committer guardplugin-directory/admin/tools/class-author-cards.php,admin/metabox/class-author-card.phpsupport-forums/inc/class-directory-compat.php— author/contributor/support rep checks, and the support rep back-compat check, which also compared against a slug that can benullsupport-forums/inc/class-stickies-compat.php— same three checkswporg-bbp-user-badges/inc/class-plugin.php— author/contributor/support rep badgeswporg-gp-customizations/inc/class-plugin.php— GTE lookup, already safe as an address is never numeric, changed for consistencythemes/pub/wporg-login/pending-create.php— logged-in guardThe contributor check in
Capabilities::map_meta_cap()already passed the strict flag; this brings the surrounding checks in line with it.Deliberately left alone: comparisons of
$user_idagainst$post->post_author. Those compare an int against a string from the database and rely on coercion.Tests
Capabilities_Committer_Identity_Testcovers the committer check and the author fallback used when a published plugin has no committer rows, asserting both that unrelated identities are refused and that genuine committers keep access.Run with
npm run plugins:testfromenvironments/. Full suite passes at 164 tests.The test extends PHPUnit's
TestCaserather thanWP_UnitTestCase, because the bundled WordPress test case callsPHPUnit\Util\Test::parseTestMethodAnnotations(), which PHPUnit 10 removed. That is also why the three existingWP_UnitTestCasefiles are excluded inphpunit.xml. Worth its own ticket.🤖 Generated with Claude Code