Skip to content

XML-RPC: Add login credential tests and type login() params as mixed - #12462

Closed
josephscott wants to merge 12 commits into
WordPress:trunkfrom
josephscott:65600/xmlrpc-wpgetusersblogs-string-args
Closed

josephscott wants to merge 12 commits into
WordPress:trunkfrom
josephscott:65600/xmlrpc-wpgetusersblogs-string-args

Conversation

@josephscott

@josephscott josephscott commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

✅ Committed in r65023 (923c321).


This PR originally rejected non-string credentials passed to wp.getUsersBlogs. That fix has since landed in trunk more generally in r63927 (Core-66168), where wp_xmlrpc_server::login() returns a 400 IXR_Error for non-scalar credentials. After merging trunk, this PR builds on that change with test coverage and type hardening:

  • Adds tests for wp.getUsersBlogs: non-scalar credentials (arrays, objects, and null) return the 400 error, and valid credentials still return blogs on single site and multisite.
  • Extends the login() tests with null username and password cases, and a test that integer credentials, which XML-RPC clients can send as <int> values, still authenticate successfully.
  • Documents the login() parameters as mixed, since they hold untrusted client input that the method now validates itself, and asserts that they are scalar when the login succeeds (@phpstan-assert-if-true =scalar).
  • Casts the scalar credentials to strings when passing them to wp_authenticate(), which documents string parameters. As a result, authenticate filter callbacks receive '12345' rather than 12345 for integer credentials.

Trac ticket: https://core.trac.wordpress.org/ticket/65600

Use of AI Tools

AI assistance: Yes
Tool(s): Claude, Claude Code
Model(s): Opus 4.8, Opus 5.5
Used for: Writing the unit tests (Opus 4.8). Resolving merge conflicts with trunk, updating tests for trunk's behavior, adding the null and integer credential cases, the login() type changes, and fixing PHPStan errors (Claude Code with Opus 5.5); changes were reviewed by a human.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Jul 9, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props josephscott, westonruter.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@westonruter westonruter left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI-generated code review. Produced by Claude Code using the Claude Opus 5 (1M context) model (claude-opus-5[1m]), run by @westonruter. Findings were verified empirically against a local checkout (guard temporarily disabled, tests re-run) rather than by inspection alone; the verification notes are inline below. Please treat it as input to human review, not a substitute for it.


Overview

Adds a type guard to wp_xmlrpc_server::wp_getUsersBlogs() rejecting non-string username/password with IXR_Error( 400, … ), plus a new test file with a 4-case data provider.

Verification performed:

  • The bug is real: with the guard removed, wp_getUsersBlogs( array( 'user', array() ) ) throws TypeError: trim(): Argument #1 ($string) must be of type string, array given from wp_authenticate() (src/wp-includes/pluggable.php:690). The guard fixes it.
  • composer lint clean; PHPStan reports no errors on the changed lines; the new tests pass 4/4.

Issues

1. The fix is one layer too low — every other authenticated method still fatals

Confirmed empirically: wp_getPosts( array( 1, 'user', array() ) ) throws the identical TypeError. So do the other authenticated methods, because they all funnel through wp_xmlrpc_server::login(), which passes straight to wp_authenticate().

Guarding inside login() fixes all of them in one place, and needs no new translatable string:

if ( ! is_string( $username ) || ! is_string( $password ) ) {
	$this->error       = new IXR_Error( 403, __( 'Incorrect username or password.' ) );
	$this->auth_failed = true;
	return false;
}

If the narrow scope is deliberate for this ticket, it's worth stating that on Trac so the broader case isn't lost.

2. BC break: integer credentials that authenticate today start returning 400

Confirmed: with the guard removed, a user whose password is 12345 authenticates successfully via wp_getUsersBlogs( array( 'numuser', 12345 ) ). With the guard it returns a 400. IXR_Message parses <int> / <i4> / <double> / <boolean> into PHP scalars, so any client that types a numeric password as <int> regresses.

Only arrays and objects cause the fatal — scalars coerce fine (trim( 12345 ) → "12345"). is_scalar() would fix the crash with no behavior change for existing working clients:

if ( ! is_scalar( $args[0] ) || ! is_scalar( $args[1] ) ) {

The test explicitly pins the int rejection ('an integer as password'), so this reads as a deliberate choice — it should be called out on the ticket rather than left implicit.

3. Objects are the untested fatal trigger, and they're reachable from the wire

class-IXR-message.php:194 turns <dateTime.iso8601> into an IXR_Date object, so an object is not a synthetic case — a client can put one in the password slot. trim( $object ) is the same TypeError. The data provider covers arrays and an int but no object; adding a new stdClass (or IXR_Date) case would cover the other half of the actual crash surface.

4. Test docblock overstates the array-username case

Verified: array( array(), '12345' ) does not fatal. sanitize_user() → wp_strip_all_tags() already guards non-scalars, so it emits an E_USER_WARNING and falls through to a normal 403. Only the password fatals. The docblock — "instead of triggering a fatal error" — is accurate for the password only. Hardening the username is still correct; just worth rewording.

Style / conventions

Measured against the sibling tests/phpunit/tests/xmlrpc/demo/addTwoNumbers.php, which uses the same error-code and message pattern:

  • Assert the message, not just the code. minimum_args() also returns 400 ('Insufficient arguments…'), so assertSame( 400, $result->code ) alone doesn't prove which branch fired. addTwoNumbers asserts $result->message too — same here.
  • Missing @covers wp_xmlrpc_server::wp_getUsersBlogs class-level annotation (the sibling has it).
  • Provider return type: the sibling uses public function data_valid_integers(): array. Consider public static function data_non_string_credentials(): array — static is PHPUnit 10-ready (core currently has ~196 static vs ~959 non-static providers, so either passes review today).
  • Double space in '…method. Requires two strings.' — inconsistent with the existing '…method. Requires two integers.' in addTwoNumbers().
  • make_user_by_role( 'subscriber' ) in the test is dead setup — the guard returns before authentication. Harmless, but it implies a dependency that isn't there.

Missing coverage

  • No positive case confirming valid string credentials still delegate correctly to blogger_getUsersBlogs(). Worth one test so a future tightening of the guard can't silently break the happy path.
  • No null, float, bool, or object cases.
  • No multisite (@group ms-required) run. The guard precedes the is_multisite() branch so this is low risk, but the paths diverge right after it.

Security & performance

Net positive: converts a PHP fatal — trivially triggerable by an unauthenticated request, and capable of leaking a stack trace with display_errors on — into a controlled 400. Two is_string() calls, no measurable cost. The error message is a static translated string with no user input reflected.

Recommendation

Sound fix for the reported symptom. Before landing, I'd want the is_scalar vs is_string BC question settled on the ticket (issue 2), an object case in the provider (issue 3), and message assertions in the tests. Moving the guard into login() (issue 1) is the higher-value change if the ticket scope allows it.

@josephscott

Copy link
Copy Markdown
Contributor Author

@westonruter can we look at getting this merged in time for WP 7.2?

westonruter and others added 5 commits October 29, 2026 11:54
Trunk now rejects non-scalar credentials early in `wp_xmlrpc_server::login()` with a 400 `IXR_Error`, superseding this branch's `elseif` that converted them into a failed login. Conflicts are resolved in favor of trunk in both `class-wp-xmlrpc-server.php` and `tests/phpunit/tests/xmlrpc/basic.php`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`wp_xmlrpc_server::login()` in trunk now rejects non-scalar credentials with a 400 `IXR_Error` saying they should be strings, rather than the 403 failed-login error this branch originally produced.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adds `null` username and password cases to the non-scalar credentials data provider, and a test that integer credentials, which XML-RPC clients can send as `<int>` values, still authenticate successfully. These were covered by this branch's tests before they were replaced by trunk's in the merge.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`wp_xmlrpc_server::login()` now validates its credentials itself, so its parameters are documented as `mixed`, matching the untrusted values XML-RPC clients send. On success it asserts that both are scalar, using the equality form (`=scalar`) so that calls with literal strings are not reported as always evaluating to true.

The scalar credentials are cast to strings when passed to `wp_authenticate()`, which documents string parameters.

The `@phpstan-ignore` comments for non-string arguments in the login tests are no longer needed and are removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Asserts that each returned blog is an array before reading its fields, ignores the intentional non-string arguments passed to `wp_getUsersBlogs()` (as the login tests do), and gives the data provider a precise return type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment on lines +308 to +310
} elseif ( ! is_scalar( $username ) || ! is_scalar( $password ) ) {
// A request can supply an array or object, which wp_authenticate() cannot handle.
$user = new WP_Error( 'invalid_credentials' );

@westonruter westonruter Oct 29, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change ended up landing previously in 9e12320.

@westonruter westonruter changed the title XML-RPC: wp.getUsersBlogs, enforce arg string requirements XML-RPC: Add login credential tests and type login() params as mixed Oct 29, 2026
westonruter and others added 2 commits October 29, 2026 12:26
`wp_xmlrpc_server::login_pass_ok()` passes its arguments straight to `login()`, so it now documents the same `mixed` parameters and the same scalar assertions on success.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The integer credentials test now checks that the login returns the user created with those credentials, not just any `WP_User`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
wporg-sync pushed a commit that referenced this pull request Oct 29, 2026
The fatal error from non-scalar credentials passed to `wp.getUsersBlogs` was fixed for all authenticated methods in r63927, which rejects them in `wp_xmlrpc_server::login()`. Tests are now added at the `wp.getUsersBlogs` level, where the error was originally reported, along with `null` credential cases and a test that integer credentials, which XML-RPC clients can send as `<int>` values, still authenticate the matching user.

The credential parameters of `wp_xmlrpc_server::login()` and `wp_xmlrpc_server::login_pass_ok()` are now documented as `mixed`, since they hold untrusted client input that `login()` validates, and are asserted to be scalar on success. This resolves static analysis errors in the methods that pass raw request arguments to `login()`. The scalar credentials are also cast to strings for `wp_authenticate()`, so `authenticate` filter callbacks now receive a string even when the client sent an integer.

Developed in #12462.
Follow-up to r63006, r63927.

Props josephscott, westonruter.
See #66168.
Fixes #65600.


git-svn-id: https://develop.svn.wordpress.org/trunk@65023 602fd350-edb4-49c9-b593-d223f7449a82
@github-actions

Copy link
Copy Markdown

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 65023
GitHub commit: 923c321

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions Bot closed this Oct 29, 2026
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Oct 29, 2026
The fatal error from non-scalar credentials passed to `wp.getUsersBlogs` was fixed for all authenticated methods in r63927, which rejects them in `wp_xmlrpc_server::login()`. Tests are now added at the `wp.getUsersBlogs` level, where the error was originally reported, along with `null` credential cases and a test that integer credentials, which XML-RPC clients can send as `<int>` values, still authenticate the matching user.

The credential parameters of `wp_xmlrpc_server::login()` and `wp_xmlrpc_server::login_pass_ok()` are now documented as `mixed`, since they hold untrusted client input that `login()` validates, and are asserted to be scalar on success. This resolves static analysis errors in the methods that pass raw request arguments to `login()`. The scalar credentials are also cast to strings for `wp_authenticate()`, so `authenticate` filter callbacks now receive a string even when the client sent an integer.

Developed in WordPress/wordpress-develop#12462.
Follow-up to r63006, r63927.

Props josephscott, westonruter.
See #66168.
Fixes #65600.

Built from https://develop.svn.wordpress.org/trunk@65023


git-svn-id: http://core.svn.wordpress.org/trunk@64173 1a063a9b-81f0-0310-95a4-ce76da25c4cd
arshidkv12 pushed a commit to arshidkv12/wordpress-develop that referenced this pull request Nov 21, 2026
The fatal error from non-scalar credentials passed to `wp.getUsersBlogs` was fixed for all authenticated methods in r63927, which rejects them in `wp_xmlrpc_server::login()`. Tests are now added at the `wp.getUsersBlogs` level, where the error was originally reported, along with `null` credential cases and a test that integer credentials, which XML-RPC clients can send as `<int>` values, still authenticate the matching user.

The credential parameters of `wp_xmlrpc_server::login()` and `wp_xmlrpc_server::login_pass_ok()` are now documented as `mixed`, since they hold untrusted client input that `login()` validates, and are asserted to be scalar on success. This resolves static analysis errors in the methods that pass raw request arguments to `login()`. The scalar credentials are also cast to strings for `wp_authenticate()`, so `authenticate` filter callbacks now receive a string even when the client sent an integer.

Developed in WordPress#12462.
Follow-up to r63006, r63927.

Props josephscott, westonruter.
See #66168.
Fixes #65600.


git-svn-id: https://develop.svn.wordpress.org/trunk@65023 602fd350-edb4-49c9-b593-d223f7449a82
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants