Repository navigation
Conversation
`wp_signups.activation_key` stored activation keys as plain text (e.g. `7259c714857ef009`), unlike `wp_users.user_activation_key` which already stores a `timestamp:hash` pair. This was assigned CVE-2017-14990. This patch brings `wp_signups` into line with `wp_users`: - `wpmu_signup_blog()` and `wpmu_signup_user()` now hash the key with phpass before storing it (`timestamp:phpass_hash` format), mirroring the approach used for password-reset keys in [25696]. - `wpmu_activate_signup()` verifies the submitted key against the stored hash and enforces a 24-hour expiry via the new `activate_signup_expiration` filter. - Legacy plain-text keys (rows created before the upgrade) continue to work for backwards compatibility so no pending activations are broken by the upgrade. - Activation URLs now include `&signup_id=N` so the correct row can be fetched for hash verification without a full-table scan. - `wp-activate.php` gains a Signup ID field on the manual activation form. - Unit tests cover: hashed storage, successful activation, wrong key rejection, wrong signup_id rejection, legacy key BC, expiry, and the `activate_signup_expiration` filter. Props bor0, tomdxw, jeremyfelt, SergeyBiryukov, SirLouen, dmsnell. Fixes #38474. == Testing Instructions == === Automated (PHPUnit) === Requires the Docker-based local environment: npm install # edit .env: set LOCAL_MULTISITE=true npm run env:start npm run env:install # New tests for this ticket: npm run test:php -- -c tests/phpunit/multisite.xml \ --filter Tests_Multisite_wpmuActivateSignup # Regression: existing test that was updated: npm run test:php -- -c tests/phpunit/multisite.xml \ --filter test_should_not_fail_for_data_used_by_a_deleted_user All 9 tests should pass. === Manual (browser) === 1. HASHED KEY IN DB - Go to /wp-signup.php as a logged-out user and register. - Check wp_signups: activation_key should look like "1700000000:$P$Bxxx..." not a plain 16-char hex string. 2. ACTIVATION LINK WORKS - The confirmation email link includes both key= and signup_id=. - Clicking it shows "Your account is now active!" 3. SIGNUP ID FIELD ON FORM - Visit /wp-activate.php with no params. - The manual entry form should show both "Activation Key" and "Signup ID" fields. 4. WRONG KEY REJECTED - Visit /wp-activate.php?key=WRONGKEY&signup_id=<valid_id> - Activation must fail (no "now active" message). 5. LEGACY KEY BACKWARDS COMPAT - Insert a row with a plain-text activation_key directly into wp_signups (simulating a pre-upgrade pending activation). - Visit /wp-activate.php?key=<plain_key>&signup_id=<id> - Activation should succeed -- pre-upgrade pending activations must not be broken by the upgrade. 6. EXPIRY - Add add_filter('activate_signup_expiration', fn() => -1) to an mu-plugin, sign up, try to activate. - Activation should fail with an expired-key error. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
|
Hi there! 👋 Thank you for your contribution to WordPress! 💖 It looks like this is your first pull request to No one monitors this repository for new pull requests. Pull requests must be attached to a Trac ticket to be considered for inclusion in WordPress Core. To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description. Pull requests are never merged on GitHub. The WordPress codebase continues to be managed through the SVN repository that this GitHub repository mirrors. Please feel free to open pull requests to work on any contribution you are making. More information about how GitHub pull requests can be used to contribute to WordPress can be found in the Core Handbook. Please include automated tests. Including tests in your pull request is one way to help your patch be considered faster. To learn about WordPress' test suites, visit the Automated Testing page in the handbook. If you have not had a chance, please review the Contribute with Code page in the WordPress Core Handbook. The Developer Hub also documents the various coding standards that are followed:
Thank you, |
|
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: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
- Multi-item associative arrays: each value on its own line - Space after function keyword in anonymous/arrow functions - Inline closure expanded to multi-line (brace must be last content on line) Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Replaces the phpass approach with HMAC-SHA256 per feedback from @dmsnell in comment:29. Instead of storing timestamp:phpass_hash and requiring signup_id as a second lookup parameter, we now: - Build a triplet: user_email:timestamp:random_key - Store base64(HMAC-SHA256(triplet, AUTH_KEY+AUTH_SALT)) in the DB (44 chars, fits the existing varchar(50) column) - Send base64url(triplet) as the activation URL parameter On activation the triplet is decoded from the URL, the HMAC is recomputed, and the row is found with a direct indexed lookup: WHERE user_email = %s AND activation_key = %s This eliminates signup_id from URLs entirely. Legacy plain-text keys (pre-upgrade pending activations) continue to work via a fallback WHERE activation_key = %s path. Props bor0, dmsnell, tomdxw, jeremyfelt, SergeyBiryukov, SirLouen. Fixes #38474. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
- Extract `_wp_generate_signup_key()` helper to deduplicate the
triplet/payload/hash logic shared between `wpmu_signup_blog()` and
`wpmu_signup_user()`. Uses `random_bytes()` where available for
better entropy, and a single `time()` call throughout.
- Tighten legacy key detection: `preg_match('~^[0-9a-f]{16}$~', $key)`
explicitly matches the original MD5-substr format instead of falling
through a broad else branch.
- Add test asserting the stored activation key is ≤ 60 chars for
compatibility with legacy table schemas (e.g. DO_NOT_UPGRADE_GLOBAL_TABLES).
- Fix legacy key test fixtures to use valid 16-char hex keys.
Props peterwilsoncc, dmsnell.
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
|
Thanks @dmsnell, @peterwilsoncc - addressed your comments, lmk how this looks! 🙇♂️ |
- Extract _wp_resolve_signup_key() to pair with _wp_generate_signup_key(), handling both new HMAC and legacy hex formats per @dmsnell's suggestion. - Apply expiration check to legacy keys via $signup->registered, eliminating the asymmetric behaviour flagged by @dmsnell. - Add docblock note to _wp_generate_signup_key() about salt rotation invalidating pending activations. - Add PHPUnit test for expired legacy key rejection. Props dmsnell. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
dmsnell
left a comment
There was a problem hiding this comment.
While looking for after_signup_user filters I saw that BuddyPress calls do_action() on it, sending an activation key.
We probably want to think about flows that call this rather than hook into it
cc: @JJJ for your thoughts on this change
| * @param string $user The user's requested login name. | ||
| * @param string $user_email The user's email address. | ||
| * @param string $key The user's activation key. | ||
| * @param string $payload The URL-safe base64-encoded activation payload sent via email. |
There was a problem hiding this comment.
this warrants a @since tag on the filter noting the change, but it might require some other consideration. what are plugins using this $key value for. in one sense, the change is superficial and this should be an opaque token; on the other hand, previously it was a value stored in the database and now it’s something else.
we might want to continue to return the database-stored value and expose the payload some other way, if that’s what plugin depend on. I did not do a more in-depth analysis; might be a good task for an LLM
There was a problem hiding this comment.
I added a @SInCE tag.
I also ran some quick analysis with Claude (searched GitHub for code that hooks after_signup_user and after_signup_site, found ~8 distinct plugin usages).
Passing $payload seems correct for all actual listeners. The only BC gap is plugins that fire the hook themselves with $signup->activation_key (wp-graphql-buddypress and GRead), those will need to update to pass the payload instead.
| // New HMAC format: email:timestamp:random. | ||
| list( $email, $timestamp, $random ) = $parts; | ||
| return array( | ||
| 'format' => 'new', |
There was a problem hiding this comment.
let’s avoid terms like “new” and “legacy”, preferring semantically rich terms which can identify the format concretely
perhaps hmac:email:timestamp:random and md5 or v1 and v2 with a description in the docblock
v1 - md5 of random number blah blah (deprecated in 7.1.0)
v2 - hmac of email:timstamp:random
There was a problem hiding this comment.
Thanks for this comment. I just want to highlight the value of such comments that is still rare to see in reviews nowadays. Data structures with proper devex are tricky to build :)
I didn't like the hmac:... because it's too long (I think it adds more burden than help), so went ahead with short ones like hmac_sha256 and md5. Would be great to get your thoughts on it
| if ( 'new' === $resolved['format'] ) { | ||
| $signup = $wpdb->get_row( | ||
| $wpdb->prepare( | ||
| "SELECT * FROM $wpdb->signups WHERE user_email = %s AND activation_key = %s", |
There was a problem hiding this comment.
with the use of the HMAC, we can remove the constraint on the email as well, right? perhaps this means we could plausibly expect more than one, but as with the signup_id, I think we want to eliminate the variability that we introduce when mixing a secret value (the hash) and a known value (the email address) since that provides an opportunity to expose information about the generation of the hash and gives someone the ability to try different payloads using the same email.
granted, I think given the payload and entropy already in the key this should be a rare problem, but I wonder if further-filtering by email has a benefit, even while it introduces this risk
There was a problem hiding this comment.
Ah, that's actually a good catch!
I wonder if further-filtering by email has a benefit
The only thing that comes to my mind is the entropy thing you already mentioned. Claude agreed with you that the extra clause is redundant:
Birthday bound on a 256-bit output. With ~10^9 total WordPress signups ever created (generous upper bound), the probability of any collision is roughly 2^30 / 2^256 ≈ 10^−68. Effectively zero.
It also brought bruteforcing for some reason 🤷 it was fun though
❯ why did you bring bruteforcing?
⏺ Fair point — brute force isn't relevant here. The question was about whether the email constraint in the WHERE clause adds security value when the HMAC already binds the email. The only meaningful number is the collision probability: ~10^−68. It's zero.
- Rename format identifiers 'new'/'legacy' to concrete 'hmac_sha256'/'md5' - Remove email from hmac_sha256 DB lookup (HMAC already binds the email) - Add @SInCE 6.9.0 BC note to after_signup_user/after_signup_site docblocks Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
| * Note: Activation links are invalidated when the site's authentication keys or salts | ||
| * change, consistent with how WordPress invalidates login sessions on salt rotation. | ||
| * | ||
| * @since 6.9.0 |
| * @access private | ||
| * | ||
| * @param string $user_email The user's email address, embedded in the payload. | ||
| * @return array { |
There was a problem hiding this comment.
this disagrees with the returned value. we’re missing key
while we’re at it, it wouldn’t hurt to return something like 'type' => 'hmac_sha256' especially for debugging purposes
There was a problem hiding this comment.
while we’re add it, let’s add @see _wp_resolve_signup_key() in this docblock and @see _wp_generate_signup_key() in the other. I can do this before merge if you prefer.
| * | ||
| * Handles two key formats: | ||
| * | ||
| * - `hmac_sha256` (introduced in 6.9.0): a URL-safe base64-encoded triplet |
There was a problem hiding this comment.
6.9 released two versions ago. all of these references need updating to 7.1.0
| $signup = $wpdb->get_row( | ||
| $wpdb->prepare( "SELECT * FROM $wpdb->signups WHERE activation_key = %s", $resolved['hash'] ) | ||
| ); | ||
| } |
There was a problem hiding this comment.
these are running the same code, are they not? so why separate them into a conditional branch?
| // For md5 (legacy) keys, fall back to the registered column in the database. | ||
| $issued_at = 'hmac_sha256' === $resolved['format'] | ||
| ? $resolved['timestamp'] | ||
| : (int) mysql2date( 'U', $signup->registered ); |
There was a problem hiding this comment.
curious if this is even worth splitting. theoretically the resolved timestamp ought to be identical to the registered value, no?
I don’t have any great insight here, just raising the question.
Per feedback from @dmsnell: - Bump all @SInCE tags from 6.9.0 to 7.1.0 in _wp_generate_signup_key(), _wp_resolve_signup_key(), wpmu_activate_signup(), and the after_signup_site/ after_signup_user hook changelogs. - Fix _wp_generate_signup_key() @return to document the missing `key` field; add `type => 'hmac_sha256'` to the return array and docblock for debuggability. - Add @see cross-references between _wp_generate_signup_key() and _wp_resolve_signup_key(). - Collapse the duplicate if/else SQL query branches in wpmu_activate_signup() into a single query with a combined comment. - Expand the timestamp ternary comment to explain why the split is load-bearing: the hmac_sha256 payload timestamp is cryptographically bound and cannot be extended by modifying the database. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
dmsnell
left a comment
There was a problem hiding this comment.
GitHub no longer allows leaving review comments without text here, so here is some text.
Co-authored-by: Dennis Snell <dennis.snell@automattic.com>
Summary
wp_signups.activation_keystored activation keys as plain text. This patches it to use HMAC-SHA256, following a suggestion from @dmsnell in the ticket thread.email:timestamp:random_keyis built;base64(HMAC-SHA256(triplet, AUTH_KEY+AUTH_SALT))(44 chars) is stored in the DB;base64url(triplet)is sent in the activation email.WHERE user_email = %s AND activation_key = %s— a direct indexed lookup, no extra URL parameter needed.[0-9a-f]{16}format — so no pending activations are broken by the upgrade. Legacy keys are also now subject to the same expiration check (viaregisteredcolumn) as new keys.activate_signup_expirationfilter (default:DAY_IN_SECONDS) controls key expiry, checked from the timestamp embedded in the triplet for new keys, and from$signup->registeredfor legacy keys._wp_generate_signup_key()helper used by both signup functions, withrandom_bytes()where available. A companion_wp_resolve_signup_key()helper handles parsing and DB-lookup-key resolution for both new and legacy formats.Fixes #38474. See also: https://core.trac.wordpress.org/ticket/38474
Props bor0, tomdxw, jeremyfelt, SergeyBiryukov, SirLouen, dmsnell, peterwilsoncc.
Test plan
Automated (PHPUnit)
All 10 tests should pass.
Manual
Hashed key in DB — Register at
/wp-signup.phpas a logged-out user. Checkwp_signups.activation_key: should be a ~44-char base64 string (e.g.5c4hlLJIcvtSnse3cuKo93pVWx2KBNOPan4HHpN7mfs=), not a plain hex string.Activation link works — The confirmation email link contains just
key=<base64url_triplet>(nosignup_id). Clicking it shows "Your account is now active!"Wrong key rejected — Visit
/wp-activate.php?key=WRONGKEY. Activation must fail.Legacy key BC — Insert a row into
wp_signupswith a 16-char hexactivation_keyand a recentregisteredtimestamp. Visiting/wp-activate.php?key=<hex_key>should still succeed — existing pending activations must not break after upgrade.Expired legacy key rejected — Insert a row into
wp_signupswith a 16-char hexactivation_keyand aregisteredtimestamp older thanDAY_IN_SECONDS. Activation must fail with an expired-key error.Expiry (new format) — Add
add_filter('activate_signup_expiration', fn() => -1)to an mu-plugin, sign up, try to activate. Must fail with an expired-key error.🤖 Generated with Claude Code