Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 5, 2025

Implementation complete: Avoid exposing sensitive argument values to STDOUT when using --prompt

Summary

  • Explored repository structure and understood the issue
  • Added mechanism to mark arguments as sensitive in DocParser (using YAML sensitive: true)
  • Updated assoc_args_to_str to accept a list of sensitive keys and mask their values with [REDACTED]
  • Modified Subcommand::invoke to filter sensitive arguments before logging
  • Added comprehensive test cases (Behat + PHPUnit)
  • Verified backward compatibility with all existing assoc_args_to_str calls
  • Validated implementation with test scripts
  • Refactored to reduce code duplication (extracted get_docparser method)
  • Fixed pre-existing bug in foreach loop
  • Addressed all code review feedback
  • Simplified conditional structure using elseif per review feedback

Changes

  1. php/utils.php: Added optional $sensitive_args parameter to assoc_args_to_str(), simplified conditional structure
  2. php/WP_CLI/Dispatcher/Subcommand.php: Added sensitive argument detection and masking logic
  3. tests/UtilsTest.php: Added unit tests for masking functionality
  4. features/prompt.feature: Added end-to-end test scenario

Usage

Command authors mark arguments as sensitive using YAML metadata:

/**
 * [--password=<value>]
 * : A password.
 * ---
 * sensitive: true
 * ---
 */

Result

Before: wp config create --dbpass='secretpass123'
After: wp config create --dbpass='[REDACTED]'

✅ Fully backward compatible
✅ Well tested
✅ Ready for review

Original prompt

This section details on the original issue you should resolve

<issue_title>Avoid exposing secure argument values to STDOUT when using --prompt</issue_title>
<issue_description>--prompt is a global parameter that allows for passing input to stdin, instead of specifying it on the CLI. This is useful for passing confidential information, such as passwords (documented as a common use case @ https://developer.wordpress.org/cli/commands/config/create/#examples).

In case of an error, WP-CLI outputs the full command it runs to stdout. When using --prompt, WP-CLI runs a different command than the user-specified one, as the parameters and arguments specified in --prompt are added to the cmdline.

When using --prompt=dbpass, the stdin value of dbpass (--dbpass='test') is echoed to stdout:

$ /usr/local/bin/wp config create --dbname=wordpress --dbuser=wordpress --dbhost=localhost --prompt=dbpass --path=wp
1/10 [--dbpass=<dbpass>]: test
# This is stdout
wp config create --dbname='wordpress' --dbuser='wordpress' --dbhost='localhost' --dbpass='test' --dbprefix='wp_' --dbcharset='utf8' --dbcollate=''
# This is stderr
ERROR 1045 (28000): Access denied for user 'wordpress'@'localhost' (using password: YES)

This defeats the purpose of using --prompt for security, as stdout may end up in logs and user terminals.

I think it would be useful to hide parameters/arguments specified using --prompt from the cmdline in stdout.

P.S. I'm aware that --quiet suppresses stdout output, but having stdout can be useful for debugging.</issue_description>

<agent_instructions>Instead of secure it should be named sensitive</agent_instructions>

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

@danielbachhuber Thanks for the report, @WilliamDEdwards !

I can confirm the behavior you're describing:

$ wp core config --prompt
1/14 --dbname=<dbname>: dbtest
2/14 --dbuser=<dbuser>: dbtest
3/14 [--dbpass=<dbpass>]: dbtest
4/14 [--dbhost=<dbhost>]:
5/14 [--dbprefix=<dbprefix>]:
6/14 [--dbcharset=<dbcharset>]:
7/14 [--dbcollate=<dbcollate>]:
8/14 [--locale=<locale>]:
9/14 [--extra-php] (Y/n):
10/14 [--skip-salts] (Y/n):
11/14 [--skip-check] (Y/n):
12/14 [--force] (Y/n):
13/14 [--config-file=<path>]:
14/14 [--insecure] (Y/n):
wp config create --dbname='dbtest' --dbuser='dbtest' --dbpass='dbtest' --dbhost='localhost' --dbprefix='wp_' --dbcharset='utf8' --dbcollate=''
ERROR 1045 (28000): Access denied for user 'dbtest'@'localhost' (using password: YES)

It looks like this behavior was added with #5322 for #4995

The original "secure" implementation of --prompt was #3531, and you can see the history here: #129

In this case, I think we should automatically obscure the "secure" arguments we don't want to display (no additional flag). We can improve our argument options API to support a secure attribute:

diff --git a/src/Config_Command.php b/src/Config_Command.php
index 70073d70..5bc107d0 100644
--- a/src/Config_Command.php
+++ b/src/Config_Command.php
@@ -65,6 +65,9 @@ class Config_Command extends WP_CLI_Command {
 	 *
 	 * [--dbpass=<dbpass>]
 	 * : Set the database user password.
+	 * ---
+	 * secure: true
+	 * ---
 	 *
 	 * [--dbhost=<dbhost>]
 	 * : Set the database host.

If secure=true, then the value should be obscured in STDOUT.</comment_new>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 4 commits November 5, 2025 13:46
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Avoid exposing secure argument values to stdout with --prompt Mask sensitive argument values in --prompt output Nov 5, 2025
Copilot AI requested a review from swissspidy November 5, 2025 14:04
@codecov
Copy link

codecov bot commented Nov 5, 2025

Codecov Report

❌ Patch coverage is 96.29630% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
php/WP_CLI/Dispatcher/Subcommand.php 95.65% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
@schlessera schlessera merged commit 90e2021 into main Dec 9, 2025
51 of 58 checks passed
@schlessera schlessera deleted the copilot/fix-secure-argument-exposure branch December 9, 2025 15:03
@schlessera schlessera added this to the 3.0.0 milestone Dec 9, 2025
Copilot AI mentioned this pull request Dec 20, 2025
43 tasks
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.

Avoid exposing secure argument values to STDOUT when using --prompt

3 participants