Skip to content

Commit 85d00ec

Browse files
committed
Security: Add the SensitiveParameter attribute to sensitive parameters.
Values passed to parameters with this attribute will be redacted if present in a stack trace when using PHP 8.2 or later. This reduces the chance that passwords and security keys get accidentally exposed in debug logs and bug reports. Props petitphp, TobiasBg, jrf, johnbillion. Fixes #57304 git-svn-id: https://develop.svn.wordpress.org/trunk@59754 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 8711aa5 commit 85d00ec

File tree

10 files changed

+178
-29
lines changed

10 files changed

+178
-29
lines changed

src/wp-admin/includes/class-wp-importer.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,13 @@ public function cmpr_strlen( $a, $b ) {
195195
* @param bool $head
196196
* @return array
197197
*/
198-
public function get_page( $url, $username = '', $password = '', $head = false ) {
198+
public function get_page(
199+
$url,
200+
$username = '',
201+
#[\SensitiveParameter]
202+
$password = '',
203+
$head = false
204+
) {
199205
// Increase the timeout.
200206
add_filter( 'http_request_timeout', array( $this, 'bump_request_timeout' ) );
201207

src/wp-admin/includes/upgrade.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,16 @@
4444
* @type string $password_message The explanatory message regarding the password.
4545
* }
4646
*/
47-
function wp_install( $blog_title, $user_name, $user_email, $is_public, $deprecated = '', $user_password = '', $language = '' ) {
47+
function wp_install(
48+
$blog_title,
49+
$user_name,
50+
$user_email,
51+
$is_public,
52+
$deprecated = '',
53+
#[\SensitiveParameter]
54+
$user_password = '',
55+
$language = ''
56+
) {
4857
if ( ! empty( $deprecated ) ) {
4958
_deprecated_argument( __FUNCTION__, '2.6.0' );
5059
}
@@ -563,7 +572,13 @@ function wp_install_maybe_enable_pretty_permalinks() {
563572
* @param string $password Administrator's password. Note that a placeholder message is
564573
* usually passed instead of the actual password.
565574
*/
566-
function wp_new_blog_notification( $blog_title, $blog_url, $user_id, $password ) {
575+
function wp_new_blog_notification(
576+
$blog_title,
577+
$blog_url,
578+
$user_id,
579+
#[\SensitiveParameter]
580+
$password
581+
) {
567582
$user = new WP_User( $user_id );
568583
$email = $user->user_email;
569584
$name = $user->user_login;

src/wp-includes/class-wp-application-passwords.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,10 @@ protected static function set_user_application_passwords( $user_id, $passwords )
459459
* @param string $raw_password The raw application password.
460460
* @return string The chunked password.
461461
*/
462-
public static function chunk_password( $raw_password ) {
462+
public static function chunk_password(
463+
#[\SensitiveParameter]
464+
$raw_password
465+
) {
463466
$raw_password = preg_replace( '/[^a-z\d]/i', '', $raw_password );
464467

465468
return trim( chunk_split( $raw_password, 4, ' ' ) );

src/wp-includes/class-wp-xmlrpc-server.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,11 @@ public function addTwoNumbers( $args ) {
285285
* @param string $password User's password.
286286
* @return WP_User|false WP_User object if authentication passed, false otherwise.
287287
*/
288-
public function login( $username, $password ) {
288+
public function login(
289+
$username,
290+
#[\SensitiveParameter]
291+
$password
292+
) {
289293
if ( ! $this->is_enabled ) {
290294
$this->error = new IXR_Error( 405, sprintf( __( 'XML-RPC services are disabled on this site.' ) ) );
291295
return false;
@@ -330,7 +334,11 @@ public function login( $username, $password ) {
330334
* @param string $password User's password.
331335
* @return bool Whether authentication passed.
332336
*/
333-
public function login_pass_ok( $username, $password ) {
337+
public function login_pass_ok(
338+
$username,
339+
#[\SensitiveParameter]
340+
$password
341+
) {
334342
return (bool) $this->login( $username, $password );
335343
}
336344

src/wp-includes/class-wpdb.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,13 @@ class wpdb {
749749
* @param string $dbname Database name.
750750
* @param string $dbhost Database host.
751751
*/
752-
public function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) {
752+
public function __construct(
753+
$dbuser,
754+
#[\SensitiveParameter]
755+
$dbpassword,
756+
$dbname,
757+
$dbhost
758+
) {
753759
if ( WP_DEBUG && WP_DEBUG_DISPLAY ) {
754760
$this->show_errors();
755761
}

src/wp-includes/ms-functions.php

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,16 @@ function wpmu_signup_user( $user, $user_email, $meta = array() ) {
938938
* @param array $meta Optional. Signup meta data. By default, contains the requested privacy setting and lang_id.
939939
* @return bool
940940
*/
941-
function wpmu_signup_blog_notification( $domain, $path, $title, $user_login, $user_email, $key, $meta = array() ) {
941+
function wpmu_signup_blog_notification(
942+
$domain,
943+
$path,
944+
$title,
945+
$user_login,
946+
$user_email,
947+
#[\SensitiveParameter]
948+
$key,
949+
$meta = array()
950+
) {
942951
/**
943952
* Filters whether to bypass the new site email notification.
944953
*
@@ -1073,7 +1082,13 @@ function wpmu_signup_blog_notification( $domain, $path, $title, $user_login, $us
10731082
* @param array $meta Optional. Signup meta data. Default empty array.
10741083
* @return bool
10751084
*/
1076-
function wpmu_signup_user_notification( $user_login, $user_email, $key, $meta = array() ) {
1085+
function wpmu_signup_user_notification(
1086+
$user_login,
1087+
$user_email,
1088+
#[\SensitiveParameter]
1089+
$key,
1090+
$meta = array()
1091+
) {
10771092
/**
10781093
* Filters whether to bypass the email notification for new user sign-up.
10791094
*
@@ -1175,7 +1190,10 @@ function wpmu_signup_user_notification( $user_login, $user_email, $key, $meta =
11751190
* @param string $key The activation key provided to the user.
11761191
* @return array|WP_Error An array containing information about the activated user and/or blog.
11771192
*/
1178-
function wpmu_activate_signup( $key ) {
1193+
function wpmu_activate_signup(
1194+
#[\SensitiveParameter]
1195+
$key
1196+
) {
11791197
global $wpdb;
11801198

11811199
$signup = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE activation_key = %s", $key ) );
@@ -1327,7 +1345,12 @@ function wp_delete_signup_on_user_delete( $id, $reassign, $user ) {
13271345
* @param string $email The new user's email address.
13281346
* @return int|false Returns false on failure, or int $user_id on success.
13291347
*/
1330-
function wpmu_create_user( $user_name, $password, $email ) {
1348+
function wpmu_create_user(
1349+
$user_name,
1350+
#[\SensitiveParameter]
1351+
$password,
1352+
$email
1353+
) {
13311354
$user_name = preg_replace( '/\s+/', '', sanitize_user( $user_name, true ) );
13321355

13331356
$user_id = wp_create_user( $user_name, $password, $email );
@@ -1611,7 +1634,14 @@ function domain_exists( $domain, $path, $network_id = 1 ) {
16111634
* @param array $meta Optional. Signup meta data. By default, contains the requested privacy setting and lang_id.
16121635
* @return bool Whether the email notification was sent.
16131636
*/
1614-
function wpmu_welcome_notification( $blog_id, $user_id, $password, $title, $meta = array() ) {
1637+
function wpmu_welcome_notification(
1638+
$blog_id,
1639+
$user_id,
1640+
#[\SensitiveParameter]
1641+
$password,
1642+
$title,
1643+
$meta = array()
1644+
) {
16151645
$current_network = get_network();
16161646

16171647
/**
@@ -1845,7 +1875,12 @@ function wpmu_new_site_admin_notification( $site_id, $user_id ) {
18451875
* @param array $meta Optional. Signup meta data. Default empty array.
18461876
* @return bool
18471877
*/
1848-
function wpmu_welcome_user_notification( $user_id, $password, $meta = array() ) {
1878+
function wpmu_welcome_user_notification(
1879+
$user_id,
1880+
#[\SensitiveParameter]
1881+
$password,
1882+
$meta = array()
1883+
) {
18491884
$current_network = get_network();
18501885

18511886
/**
@@ -2271,7 +2306,12 @@ function add_existing_user_to_blog( $details = false ) {
22712306
* @param string $password User password. Ignored.
22722307
* @param array $meta Signup meta data.
22732308
*/
2274-
function add_new_user_to_blog( $user_id, $password, $meta ) {
2309+
function add_new_user_to_blog(
2310+
$user_id,
2311+
#[\SensitiveParameter]
2312+
$password,
2313+
$meta
2314+
) {
22752315
if ( ! empty( $meta['add_to_blog'] ) ) {
22762316
$blog_id = $meta['add_to_blog'];
22772317
$role = $meta['new_role'];

src/wp-includes/pluggable-deprecated.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,15 @@ function get_user_by_email($email) {
101101
* @param string $siteurl Optional. Will be used instead of SITECOOKIEPATH if set
102102
* @param bool $remember Optional. Remember that the user is logged in
103103
*/
104-
function wp_setcookie($username, $password = '', $already_md5 = false, $home = '', $siteurl = '', $remember = false) {
104+
function wp_setcookie(
105+
$username,
106+
#[\SensitiveParameter]
107+
$password = '',
108+
$already_md5 = false,
109+
$home = '',
110+
$siteurl = '',
111+
$remember = false
112+
) {
105113
_deprecated_function( __FUNCTION__, '2.5.0', 'wp_set_auth_cookie()' );
106114
$user = get_user_by('login', $username);
107115
wp_set_auth_cookie($user->ID, $remember);
@@ -168,7 +176,12 @@ function wp_get_cookie_login() {
168176
* @param string $deprecated Not used
169177
* @return bool True on successful check, false on login failure.
170178
*/
171-
function wp_login($username, $password, $deprecated = '') {
179+
function wp_login(
180+
$username,
181+
#[\SensitiveParameter]
182+
$password,
183+
$deprecated = ''
184+
) {
172185
_deprecated_function( __FUNCTION__, '2.5.0', 'wp_signon()' );
173186
global $error;
174187

src/wp-includes/pluggable.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,11 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array()
598598
* @return WP_User|WP_Error WP_User object if the credentials are valid,
599599
* otherwise WP_Error.
600600
*/
601-
function wp_authenticate( $username, $password ) {
601+
function wp_authenticate(
602+
$username,
603+
#[\SensitiveParameter]
604+
$password
605+
) {
602606
$username = sanitize_user( $username );
603607
$password = trim( $password );
604608

@@ -2631,7 +2635,10 @@ function wp_hash( $data, $scheme = 'auth', $algo = 'md5' ) {
26312635
* @param string $password Plain text user password to hash.
26322636
* @return string The hash string of the password.
26332637
*/
2634-
function wp_hash_password( $password ) {
2638+
function wp_hash_password(
2639+
#[\SensitiveParameter]
2640+
$password
2641+
) {
26352642
global $wp_hasher;
26362643

26372644
if ( empty( $wp_hasher ) ) {
@@ -2667,7 +2674,12 @@ function wp_hash_password( $password ) {
26672674
* @param string|int $user_id Optional. User ID.
26682675
* @return bool False, if the $password does not match the hashed password.
26692676
*/
2670-
function wp_check_password( $password, $hash, $user_id = '' ) {
2677+
function wp_check_password(
2678+
#[\SensitiveParameter]
2679+
$password,
2680+
$hash,
2681+
$user_id = ''
2682+
) {
26712683
global $wp_hasher;
26722684

26732685
// If the hash is still md5...
@@ -2863,7 +2875,11 @@ function wp_rand( $min = null, $max = null ) {
28632875
* @param string $password The plaintext new user password.
28642876
* @param int $user_id User ID.
28652877
*/
2866-
function wp_set_password( $password, $user_id ) {
2878+
function wp_set_password(
2879+
#[\SensitiveParameter]
2880+
$password,
2881+
$user_id
2882+
) {
28672883
global $wpdb;
28682884

28692885
$old_user_data = get_userdata( $user_id );

src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1310,7 +1310,12 @@ public function check_username( $value, $request, $param ) {
13101310
* @param string $param The parameter name.
13111311
* @return string|WP_Error The sanitized password, if valid, otherwise an error.
13121312
*/
1313-
public function check_user_password( $value, $request, $param ) {
1313+
public function check_user_password(
1314+
#[\SensitiveParameter]
1315+
$value,
1316+
$request,
1317+
$param
1318+
) {
13141319
$password = (string) $value;
13151320

13161321
if ( empty( $password ) ) {

0 commit comments

Comments
 (0)