Opened 12 days ago
Last modified 7 days ago
#66399 assigned defect (bug)
Secrets API: Generate `WP_SECRETS_KEY` during installation so secrets do not depend on the salts
| Reported by: | ericmann | Owned by: | ericmann |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.2 |
| Component: | Security | Version: | trunk |
| Severity: | normal | Keywords: | has-patch needs-testing |
| Cc: | Focuses: |
Description
Follow-up to [64337] (#66187). See #66380.
When WP_SECRETS_KEY is not defined, the Secrets API derives its key from LOGGED_IN_KEY and LOGGED_IN_SALT. Rotating the salts is common advice (wp config shuffle-salts, security plugins), and before 7.2 it only logged users out. On a site using that fallback it now makes every stored secret unreadable, and blocks saving new ones, until the old values are restored. #66187 comment:23 raised this, and comment:24 confirmed it on 7.2-beta2. #66380 fixes what Site Health says about it. This ticket removes the dependency for new installs.
Proposed fix
setup-config.php already generates the eight keys and salts. It should also write a WP_SECRETS_KEY define after them: a base64-encoded random 32-byte value, which is the form the Secrets API uses as raw key material. New installs then never use the fallback, and rotating the salts leaves their secrets readable.
Notes
wp-config-sample.phpstays unchanged on purpose. The Secrets API rejects the salt placeholder, but it accepts anyWP_SECRETS_KEYstring, so a placeholder in the sample would give every hand-edited install that left it alone the same public key. A site whose config was copied from the sample by hand keeps the salt fallback, and Site Health recommends a dedicated key.- Without a CSPRNG,
setup-config.phpleaves the define out rather than fall back towp_generate_password()or the secret-key API, and the site uses the salt fallback. - Existing sites are not affected. Moving one off the fallback means re-wrapping the root key, which core has no public path for yet (planned for 7.3).
- Installers that write
wp-config.phpthemselves, such as WP-CLI'swp config createand hosts' one-click installers, are out of scope here, but should do the same.
AI assistance: Claude Code (Claude Opus 5.5) for drafting the patch and this ticket. I reviewed both.
Change History (6)
This ticket was mentioned in PR #15124 on WordPress/wordpress-develop by @ericmann.
12 days ago
#1
- Keywords has-patch added; needs-patch removed
#3
@
10 days ago
- Milestone Awaiting Review → 7.2
PR 15124 is updated after @peterwilsoncc's review:
wp-config-sample.phpdefinesWP_SECRETS_KEYwith the placeholder, after the salts and outside their group.setup-config.phpfills it in with the same loop as the salts. A custom or older localized sample without the line still gets it added after the salts.- Without a CSPRNG, the key comes from
wp_generate_password(), as the salts do.
This now depends on PR 15258 (#66187), which makes WP_SECRETS_KEY required and rejects the placeholder. With the fallback gone this is more than hardening: without it, a new install has no Secrets API until someone edits wp-config.php. Adding to the 7.2 milestone unless a committer disagrees.
Tested end to end: install, store a secret, shuffle all eight salts, read it back. This was run with the new sample, with PR 15258 applied, and with the old sample. In every case there is one canonical key and the secret reads back. WP-CLI's wp config create needs the same change, and I'll open an issue there.
@ericmann commented on PR #15124:
10 days ago
#4
This is working for a manual install but a fresh install via WP-CLI. It looks like an associated PR will need to be made to wp-cli/config-command, wp-cli/core-command or both.
Added some notes inline.
Agreed. wp config create writes its own file, so it needs the same change. I'll open an issue on wp-cli/config-command. wp config shuffle-salts already touches only the eight keys and salts, so it's fine as is.
#5
follow-up:
↓ 6
@
9 days ago
Patch Testing Report
Patch tested: https://github.com/WordPress/wordpress-develop/pull/15124 (head 6c93419bd4), alone and together with https://github.com/WordPress/wordpress-develop/pull/15258 (head d7abced039), both applied to trunk r65147.
Environment
- WordPress: 7.2-beta3-64914-src (trunk r65147)
- PHP: 8.3.36
- Server: nginx/1.31.8 (wordpress-develop Docker environment)
- Database: MySQL 9.7.4
- Browser: Chrome 156.0.8078.74
- OS: macOS 27.0.1
- Theme: Ipsum 1.0
- MU Plugins:
- fix-docker-loopback 1.0.0 (added by the Docker environment)
- a local helper for another ticket that only filters
dashboard_secondary_items(unrelated)
- Plugins:
- None activated
Steps taken
- Reproduced on trunk without the PRs: on an install whose wp-config.php has no
WP_SECRETS_KEY,get_key_source()reports "derived from LOGGED_IN_KEY and LOGGED_IN_SALT". Stored a secret withwp_set_secret(), ranwp config shuffle-salts, thenwp_get_secret()returnedsecret_key_unavailable, and saving a new secret also failed withsecret_key_unavailable. - Applied PR 15124, removed wp-config.php, emptied the database, and ran the browser installer (
setup-config.phptheninstall.php). - The generated wp-config.php has exactly one
WP_SECRETS_KEYdefine, after the closing/**#@-*/of the keys and salts, with the new docblock. The value is strict base64 that decodes to 32 bytes, and is canonical.php -lreports no syntax errors. get_key_source()reports "WP_SECRETS_KEY (base64-encoded 32 bytes)".- Stored a secret, ran
wp config shuffle-salts(confirmedLOGGED_IN_SALTchanged), then read the secret back: it returned the stored value. Saving and reading a new secret after the shuffle also worked. - Older or custom sample without the
WP_SECRETS_KEYline (trunk's wp-config-sample.php): the key is added once, right after/**#@-*/, valid 32-byte base64, file passesphp -l. - Custom sample without the closing
/**#@-*/: the key is added once, right afterNONCE_SALT, valid 32-byte base64, file passesphp -l. - Applied PR 15258 on top (applies cleanly) and repeated steps 2 to 5 on an empty database: same results, and the secret still reads back after shuffling the salts.
- With both PRs, replacing the generated key with the sample placeholder makes
get_key_source()report "WP_SECRETS_KEY is defined but not usable", and saving fails with a clear message. Removing the define (aswp config createcurrently writes it) gives "WP_SECRETS_KEY is not defined." and saving fails. npm run test:php -- --group secretswith both PRs: OK, 392 tests, 983 assertions, 25 skipped.- ✅ Patch is solving the problem: new installs made through the installer get their own
WP_SECRETS_KEY, so rotating the salts no longer makes stored secrets unreadable.
Expected result
- The installer writes one valid
WP_SECRETS_KEYafter the salts, for the bundled sample, older samples and custom samples, and secrets stay readable after the salts are rotated.
Additional Notes
- With PR 15124 alone, a hand-edited wp-config.php that keeps the sample's
put your unique phrase herevalue is accepted on a fresh database:get_key_source()reports "WP_SECRETS_KEY (legacy interpretation, hashed as an opaque string)" and secrets save and read with that public value. With PR 15258 applied, the same value is rejected (step 9). So PR 15124 looks safe only together with PR 15258, as noted in comment:3. - Installs created with WP-CLI (
wp config create) still get no key, and with PR 15258 the Secrets API is then unavailable until the key is added. This matches comment:4 and the planned WP-CLI issue. - Not tested: the no-CSPRNG fallback to
wp_generate_password(), and the screen shown when wp-config.php cannot be written.
Screenshots/Screencast with results
- None; the results are command output, summarised above.
Support Content
- Commands used (WP-CLI eval through
npm run env:cli):- Key source:
( new WP_Secrets_Config_Key_Provider() )->get_key_source() - Store:
wp_set_secret( 'test-66399/demo', 'hello-66399' ) - Read:
wp_get_secret( 'test-66399/demo' )->reveal() - Rotate:
wp config shuffle-salts
- Key source:
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5 (claude-opus-5-5)
Used for: running the test steps in my local environment and drafting this report; I reviewed the results and the wording.
#6
in reply to: ↑ 5
@
7 days ago
Replying to digitalpritam:
Thanks @digitalpritam, that covers every sample the installer can meet. The two untested paths, no CSPRNG and an unwritable wp-config.php, change only where the key comes from and where it's shown. The second uses the same text area as the salts.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Without
WP_SECRETS_KEY, the Secrets API derives its key fromLOGGED_IN_KEYandLOGGED_IN_SALT, so rotating the salts makes every stored secret unreadable until the old values come back (#66187 comment:23, confirmed in comment:24). This makes new installs independent of the salts.What changes
setup-config.phpwritesWP_SECRETS_KEYas a base64-encoded random 32-byte value, the form the Secrets API uses as raw key material./**#@-*/of the keys-and-salts group, with its own docblock. The group's comment says the salts can be changed at any time, which is exactly wrong for this key. If a custom sample has no closing tag, it goes right afterNONCE_SALT.wp-config-sample.phpthat already definesWP_SECRETS_KEYis left alone, so there is never a second define.wp-config-sample.phpis unchanged. The Secrets API rejects the salt placeholder but accepts anyWP_SECRETS_KEYstring, so a placeholder there would become a public key on every hand-edited install that left it in place.Existing sites are not affected. The Site Health side is #66380.
Testing
setup-config.phphas no unit tests, so this was tested end to end on PHP 8.5 and MySQL 8: runsetup-config.php?step=2andinstall.php?step=2against a fresh database, store a secret, replace all eight keys and salts aswp config shuffle-saltsdoes, then read the secret again.WP_SECRETS_KEYin the generatedwp-config.phpsecret_key_unavailableAlso checked:
WP_SECRETS_KEYgives exactly one define, the sample's own./**#@-*/gets the key afterNONCE_SALT.php -l.phpcsreports nothing new on the file, andphpstan analysewith core's configuration passes.To test by hand: delete
wp-config.php, run the installer, and check thatWP_SECRETS_KEYfollows the salts. Then store a secret, runwp config shuffle-salts, and read the secret back.Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Drafting the patch, running the install tests above, and this description. I reviewed the change and the results.