Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
e2b0bfd
Filesystem API: Check `PHP_OS_FAMILY` instead of `php_uname()` in Pcl…
SergeyBiryukov Dec 12, 2024
b4969d4
Build/Test Tools: Remove repository specific logic from callable work…
desrosj Dec 13, 2024
ff5850e
Build/Test Tools: Trim down the upgrade testing matrix.
desrosj Dec 13, 2024
28f4e37
Build/Test Tools: Update `devDependencies`.
desrosj Dec 13, 2024
20982b7
Customize: Remove unnecessary `height: 100%` on accordion button.
joedolson Dec 13, 2024
ab51fc3
Editor: Hide 'Skip to Editor' if editor not supported.
joedolson Dec 13, 2024
85937e7
Coding Standards: Use strict comparison in `get_blog_id_from_url()`.
SergeyBiryukov Dec 13, 2024
1cc1af2
Themes: Replace "Active" wording with "Installed" in the theme instal…
audrasjb Dec 13, 2024
b03c9f5
Comments: Avoid reverting comment reply when context menu is open.
joedolson Dec 14, 2024
c3c319e
Formatting: Check the result of `preg_split()` in `convert_smilies()`.
SergeyBiryukov Dec 14, 2024
cdc2f25
Tests: Clean up `convert_smilies()` tests.
SergeyBiryukov Dec 15, 2024
0530261
Site Health: Remove use of deprecated function from `wp_is_https_supp…
felixarntz Dec 16, 2024
b670db9
Build/Test Tools: Update `slackapi/slack-github-action`.
desrosj Dec 16, 2024
716e930
Build/Test Tools: Support manual runs for the test old branch workflow.
desrosj Dec 16, 2024
8eaaf53
Build/Test Tools: Update the Codecov GitHub Action.
desrosj Dec 16, 2024
f6fb194
Editor: Check `get_user_count()` instead of `get_users()` for the loc…
SergeyBiryukov Dec 16, 2024
dab286e
Block Hooks: Enable for post content.
ockham Dec 17, 2024
8b4425a
Build/Test Tools: Add Twenty Twenty-Five to the Performance Tests.
swissspidy Dec 17, 2024
e58bef6
Build/Test Tools: Use correct tag name for the baseline version.
swissspidy Dec 17, 2024
20c0327
Build/Test Tools: Fix version number when downgrading WP in performan…
swissspidy Dec 17, 2024
ffceac5
Build/Test Tools: Use MySQL 8.4 as the default.
desrosj Dec 17, 2024
1458de7
Build/Test Tools: Regularly run the `html-api-html5lib-tests`.
desrosj Dec 17, 2024
f08e51f
Build/Test Tools: Allow more control when testing older branches.
desrosj Dec 17, 2024
8ed4cae
Build/Test Tools: Update Default Theme `devDependencies`.
desrosj Dec 17, 2024
c697356
Build/Test Tools: Document every matrix exclusion.
desrosj Dec 17, 2024
68c4efc
Privacy: Use SHA-256 hashing algorithm for Gravatar.
SergeyBiryukov Dec 17, 2024
2238011
Coding Standards: Fix WPCS issues in `get_avatar_data()`.
SergeyBiryukov Dec 18, 2024
7af0469
Build/Test Tools: Remove an unnecessary call to svn in a debugging step.
johnbillion Dec 18, 2024
537ee4a
Introduce the `wp_hash_password_algorithm` filter for controlling the…
johnbillion Dec 18, 2024
8a99edd
Why.
johnbillion Dec 18, 2024
68634f0
Vanilla bcrypt hashes should be rehashed to use pre-hashing.
johnbillion Dec 18, 2024
adf983f
Let's bring this more inline with the other tests.
johnbillion Dec 18, 2024
754519b
No need to perform a prefix check here, just let `wp_check_password()…
johnbillion Dec 18, 2024
a2107c2
External Libraries: Append a string to `react`/`react-dom` versions.
desrosj Dec 18, 2024
9e4b268
External Libraries: Append `.1` to `react`/`react-dom` versions.
peterwilsoncc Dec 19, 2024
17b50d3
Privacy: Replace hardcoded MD5 references in `wp_credits_section_list…
SergeyBiryukov Dec 19, 2024
816ec5d
Docs: Add missing single quote in `WP_User_Query::prepare_query()` Do…
SergeyBiryukov Dec 19, 2024
ef76060
Block Hooks: Apply to synced patterns.
ockham Dec 19, 2024
7381a82
REST API: Protect against fatal error for post types without format s…
peterwilsoncc Dec 19, 2024
b8ecfbf
Help/About: Add additional release squad titles to credits page.
peterwilsoncc Dec 19, 2024
a64ad57
Docs: Update parameter type hints to include `null` for post thumbnai…
SergeyBiryukov Dec 20, 2024
afc8acf
Docs: Docblock improvements in .
audrasjb Dec 21, 2024
17d5e47
Media: Fix margin issues on the Media file upload screen.
audrasjb Dec 21, 2024
08c3dd4
Login and Registration: Adjust login form margins for better consiste…
audrasjb Dec 21, 2024
322b984
Help/About: Reorder release squad titles for some consistency in tran…
SergeyBiryukov Dec 21, 2024
71eaaad
Themes: Fix unwanted horizontal scrolling in theme details screen on …
audrasjb Dec 22, 2024
de76b6e
I18n: Add translator context for various occurrences of "upload".
audrasjb Dec 22, 2024
d030306
Customizer: Allow custom accordion items with obsolete structure.
joedolson Dec 22, 2024
07be244
Coding Standards: Use strict comparison in `wp_handle_comment_submiss…
SergeyBiryukov Dec 22, 2024
a9e2f1c
Coding Standards: Use strict comparison in `wpmu_validate_user_signu…
SergeyBiryukov Dec 23, 2024
9dd87b8
Coding Standards: Fix a comment indentation issue in `script-loader.p…
audrasjb Dec 23, 2024
70ecc6b
Themes: Add an ID to the block theme skip link.
joedolson Dec 23, 2024
87f99b4
Coding Standards: Use strict comparison in `wpmu_signup_blog_notifica…
SergeyBiryukov Dec 24, 2024
27bb7ac
Coding Standards: Use strict comparison in `remove_user_from_blog()`.
SergeyBiryukov Dec 25, 2024
20110f6
Coding Standards: Use strict comparison in `get_active_blog_for_user()`.
SergeyBiryukov Dec 26, 2024
779ed48
Coding Standards: Use strict comparison in `is_user_spammy()`.
SergeyBiryukov Dec 27, 2024
4a6b12b
Options, Meta APIs: Ensure `after_section` is printed for sections wi…
SergeyBiryukov Dec 28, 2024
4e1752d
Coding Standards: Use strict comparison in `sanitize_post()`.
SergeyBiryukov Dec 29, 2024
2ba8433
Coding Standards: Use strict comparison in `get_post_ancestors()`.
SergeyBiryukov Dec 30, 2024
7fedfd4
Coding Standards: Use strict comparison in `wp_count_attachments()`.
SergeyBiryukov Dec 31, 2024
de14028
Happy New Year! 🎄
SergeyBiryukov Jan 1, 2025
238f865
Happy New Year Twenty Twenty-Five! 🎄
peterwilsoncc Jan 2, 2025
5948245
Build/Test Tools: Fix incorrect commit time being reported to WordPre…
felixarntz Jan 2, 2025
7bd6835
Build/Test Tools: Revert [59570].
felixarntz Jan 2, 2025
016bbec
Coding Standards: Use strict comparison in `_reset_front_page_setting…
SergeyBiryukov Jan 2, 2025
8da02a8
Coding Standards: Use strict comparison in `wpmu_validate_blog_signup…
SergeyBiryukov Jan 3, 2025
8f6f809
Coding Standards: Replace loose comparison in `wpmu_welcome_notificat…
SergeyBiryukov Jan 4, 2025
bb3f90f
Coding Standards: Use strict comparison in `get_pages()`.
SergeyBiryukov Jan 5, 2025
938d27a
Comments: Noindex pages containing unapproved comments.
peterwilsoncc Jan 5, 2025
d6aa043
Build/Test Tools: Expand performance tests setup.
swissspidy Jan 6, 2025
35d1885
Merge branch 'trunk' into 21022-bcrypt-algo-filter
johnbillion Jan 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 48 additions & 10 deletions src/wp-includes/pluggable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2622,22 +2622,54 @@ function wp_hash_password( $password ) {
return '*';
}

/**
* Filters the hashing algorithm to use in the password_hash() and password_needs_rehash() functions.
*
* The default is the value of the `PASSWORD_BCRYPT` constant which means bcrypt is used.
*
* **Important:** The only password hashing algorithm that is guaranteed to be available across PHP
* installations is bcrypt. If you use any other algorithm you must make sure that it is available on
* the server. The `password_algos()` function can be used to check which hashing algorithms are available.
*
* The hashing options can be controlled via the {@see 'wp_hash_password_options'} filter.
*
* Other available constants include:
*
* - `PASSWORD_ARGON2I`
* - `PASSWORD_ARGON2ID`
* - `PASSWORD_DEFAULT`
*
* @since x.y.z
*
* @param string $algorithm The hashing algorithm. Default is the value of the `PASSWORD_BCRYPT` constant.
*/
$algorithm = apply_filters( 'wp_hash_password_algorithm', PASSWORD_BCRYPT );

/**
* Filters the options passed to the password_hash() and password_needs_rehash() functions.
*
* The default hashing algorithm is bcrypt, but this can be changed via the {@see 'wp_hash_password_algorithm'}
* filter. You must ensure that the options are appropriate for the algorithm in use.
*
* @since x.y.z
*
* @param array $options Array of options to pass to the password hashing functions.
* By default this is an empty array which means the default
* options will be used.
* @param array $options Array of options to pass to the password hashing functions.
* By default this is an empty array which means the default
* options will be used.
* @param string $algorithm The hashing algorithm in use.
*/
$options = apply_filters( 'wp_hash_password_options', array() );
$options = apply_filters( 'wp_hash_password_options', array(), $algorithm );

// Algorithms other than bcrypt don't need to use pre-hashing.
if ( PASSWORD_BCRYPT !== $algorithm ) {
return password_hash( $password, $algorithm, $options );
}

// Use sha384 to retain entropy from a password that's longer than 72 bytes, and a wp-sha384 key for domain separation.
$password_to_hash = base64_encode( hash_hmac( 'sha384', trim( $password ), 'wp-sha384', true ) );

Choose a reason for hiding this comment

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

Is it necessary to provide a filter here to modify whether to pre-hash?

Copy link
Owner Author

Choose a reason for hiding this comment

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

I'm happy for WordPress to remain opinionated here and not allow pre-hashing to be disabled via a filter when bcrypt is in use.


// Add a `wp-` prefix to facilitate distinguishing vanilla bcrypt hashes.
return 'wp-' . password_hash( $password_to_hash, PASSWORD_BCRYPT, $options );
return 'wp-' . password_hash( $password_to_hash, $algorithm, $options );
}
endif;

Expand Down Expand Up @@ -2736,14 +2768,20 @@ function wp_password_needs_rehash( $hash ) {
return false;
}

if ( ! str_starts_with( $hash, 'wp-' ) ) {
return true;
}
/** This filter is documented in wp-includes/pluggable.php */
$algorithm = apply_filters( 'wp_hash_password_algorithm', PASSWORD_BCRYPT );

/** This filter is documented in wp-includes/pluggable.php */
$options = apply_filters( 'wp_hash_password_options', array() );
$options = apply_filters( 'wp_hash_password_options', array(), $algorithm );

if ( str_starts_with( $hash, 'wp-' ) ) {
$hash = substr( $hash, 3 );
} else if ( PASSWORD_BCRYPT === $algorithm ) {
// Vanilla bcrypt hashes should be rehashed to use pre-hashing.
return true;
}

return password_needs_rehash( substr( $hash, 3 ), PASSWORD_BCRYPT, $options );
return password_needs_rehash( $hash, $algorithm, $options );
}
endif;

Expand Down
6 changes: 1 addition & 5 deletions src/wp-includes/post-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -883,11 +883,7 @@ function post_password_required( $post = null ) {
}

$hash = wp_unslash( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] );
if ( ! str_starts_with( $hash, '$' ) ) {
$required = true;
} else {
$required = ! wp_check_password( $post->post_password, $hash );
}
$required = ! wp_check_password( $post->post_password, $hash );

/**
* Filters whether a post requires the user to supply a password.
Expand Down
17 changes: 17 additions & 0 deletions tests/phpunit/tests/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,23 @@ public function data_usernames() {
);
}

/**
* @ticket 21022
* @ticket 50027
*/
public function test_password_hashing_algorithm_can_be_filtered() {
$password = 'password';

$filter_count_before = did_filter( 'wp_hash_password_algorithm' );

$wp_hash = wp_hash_password( $password );

wp_check_password( $password, $wp_hash );
wp_password_needs_rehash( $wp_hash );

$this->assertSame( $filter_count_before + 2, did_filter( 'wp_hash_password_algorithm' ) );
}

/**
* @ticket 21022
* @ticket 50027
Expand Down