Skip to content

Add support for application passwords via env vars and wp-cli.yml config#151

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/add-support-for-application-passwords
Draft

Add support for application passwords via env vars and wp-cli.yml config#151
Copilot wants to merge 2 commits intomainfrom
copilot/add-support-for-application-passwords

Conversation

Copy link

Copilot AI commented Mar 19, 2026

WordPress 5.6+ application passwords could only be supplied by embedding credentials in the --http URL, exposing secrets in shell history and process listings.

Changes

  • inc/Runner.php: Extends credential resolution in load_remote_commands() to support three sources with explicit priority ordering:
Priority Source
Highest URL embedding — --http=admin:pass@example.com (existing, unchanged)
Medium WP_REST_CLI_AUTH_USER / WP_REST_CLI_AUTH_PASSWORD environment variables
Lowest http_user / http_password keys in wp-cli.yml

Usage

Environment variables (CI/CD, avoids secrets in config):

WP_REST_CLI_AUTH_USER=admin \
WP_REST_CLI_AUTH_PASSWORD="X9yS 9YYn pbaU 5H8A kJNO DEfe" \
wp --http=https://example.com rest post create --title=wibble

wp-cli.yml (persistent per-project defaults):

http_user: admin
http_password: "X9yS 9YYn pbaU 5H8A kJNO DEfe"

Application passwords with spaces work cleanly with both approaches without requiring URL encoding.

Original prompt

This section details on the original issue you should resolve

<issue_title>Add support for application passwords</issue_title>
<issue_description>## Feature Request

Describe your use case and the problem you are facing

Application passwords as a REST API authentication as added back in WordPress 5.6. This allow for authenticated requests by passing username and application password. It would be great if RESTful command fully support this.

Currently it is possible to use application password by passing username and password in the command like this.

wp rest --http=http://admin:"X9yS 9YYn pbaU 5H8A kJNO DEfe"@www.example.com post create --content=wibble --title=wibble

However, this is not espcially secure. As the password is written in plan text in the command.

Describe the solution you'd like

There are a number of ways this could be implemented,

  • New paramters.
wp rest --http=https://www.example.com --application_user=admin --application_password=password
  • Use envoriment variables
    Username and password could be read in via envoriment variables.

  • Via wp-cli.yml
    Username and password could be read in via wp-cli.yml

It would also be nice, if this command supported, application registion as well. But this is a nice to have.
</issue_description>

Comments on the Issue (you are @copilot in this section)

@danielbachhuber I'm open to a PR on this, and I don't have a strong opinion on the implementation at this point. I'd look at authentication for other CLI tools for inspiration.

Feel free to submit a pull request, if you'd like. Here is some guidance on our pull request best practices.</comment_new>


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for application passwords in REST API Add support for application passwords via env vars and wp-cli.yml config Mar 19, 2026
Copilot AI requested a review from swissspidy March 19, 2026 23:02
@codecov
Copy link

codecov bot commented Mar 19, 2026

Codecov Report

❌ Patch coverage is 0% with 11 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
inc/Runner.php 0.00% 11 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds safer ways to provide HTTP Basic Auth credentials for remote REST requests without embedding secrets in the --http URL, supporting WordPress application passwords in CI and local configs.

Changes:

  • Adds credential lookup from wp-cli.yml (http_user / http_password) as the lowest-priority source.
  • Adds credential lookup from environment variables (WP_REST_CLI_AUTH_USER / WP_REST_CLI_AUTH_PASSWORD) as a medium-priority source.
  • Preserves URL-embedded credentials as the highest-priority source.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 31 to +35
$bits = parse_url( $http );
$auth = array();

// Check wp-cli config for http_user / http_password (lowest priority).
$runner = WP_CLI::get_runner();
Copy link

Copilot AI Mar 19, 2026

Choose a reason for hiding this comment

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

parse_url( $http ) won’t extract user / pass unless the value includes a scheme (e.g. http://user:pass@host). If a user follows the documented-style --http=user:pass@example.com (no scheme), $bits['user'] will never be set and the URL-embedded credentials won’t be applied. Consider normalizing $http to include a default scheme (similar to auto_discover_api()) before calling parse_url() so credential parsing works consistently.

Copilot uses AI. Check for mistakes.
Comment on lines +42 to +46
// Environment variables override config file values (medium priority).
// An empty username is not valid for authentication, so we skip if it is empty.
// An empty password is allowed (e.g. passwordless setups), consistent with URL embedding.
$env_user = getenv( 'WP_REST_CLI_AUTH_USER' );
$env_password = getenv( 'WP_REST_CLI_AUTH_PASSWORD' );
Copy link

Copilot AI Mar 19, 2026

Choose a reason for hiding this comment

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

New credential-resolution behavior (wp-cli.yml keys + env vars + precedence ordering) is untested. Since there are already PHPUnit tests for Runner, please add coverage that verifies the priority order and a couple of edge cases (e.g. URL userinfo present vs env/config, env user set without env password). One approach is to extract auth resolution into a small pure helper so it can be unit-tested without making HTTP requests.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for application passwords

3 participants