Repository navigation
Secrets API: Fix Site Health reports and key advice that locks stored secrets #14847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mpeshev
wants to merge
3
commits into
WordPress:trunk
Choose a base branch
from
mpeshev:secrets-site-health-fixes
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -71,7 +71,37 @@ public function test_key_source_test_recommends_regeneration_for_a_legacy_key(): | |||||||||
| $result = wp_secrets_site_health_test_key_source(); | ||||||||||
|
|
||||||||||
| $this->assertSame( 'recommended', $result['status'] ); | ||||||||||
| $this->assertStringContainsString( 'generate-key', $result['description'] ); | ||||||||||
| $this->assertStringContainsString( 'can still be replaced', $result['description'] ); | ||||||||||
| $this->assertStringNotContainsString( 'generate-key', $result['description'], 'There is no such WP-CLI command in core.' ); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Replacing the key once secrets are stored would make them unreadable. | ||||||||||
| * | ||||||||||
| * @runInSeparateProcess | ||||||||||
| * @preserveGlobalState disabled | ||||||||||
| */ | ||||||||||
| public function test_key_source_test_warns_to_keep_a_legacy_key_once_secrets_are_stored(): void { | ||||||||||
| define( 'WP_SECRETS_KEY', 'not-base64-32!!' ); | ||||||||||
|
|
||||||||||
| $this->assertTrue( wp_set_secret( 'myplugin/api-key', 'value' ) ); | ||||||||||
|
|
||||||||||
| $result = wp_secrets_site_health_test_key_source(); | ||||||||||
|
|
||||||||||
| $this->assertSame( 'recommended', $result['status'] ); | ||||||||||
| $this->assertStringContainsString( 'Keep its current value', $result['description'] ); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public function test_key_source_test_is_critical_when_the_key_does_not_match_the_stored_secrets(): void { | ||||||||||
| wp_set_secret( 'myplugin/api-key', 'value' ); | ||||||||||
|
|
||||||||||
| // Stands in for a root key that was wrapped with a different site key. | ||||||||||
| update_site_option( WP_Secrets_Key_Manager::ROOT_KEY_OPTION, base64_encode( random_bytes( 72 ) ) ); | ||||||||||
|
|
||||||||||
| $result = wp_secrets_site_health_test_key_source(); | ||||||||||
|
|
||||||||||
| $this->assertSame( 'critical', $result['status'] ); | ||||||||||
| $this->assertStringContainsString( 'Restoring the previous value', $result['description'] ); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
|
|
@@ -98,6 +128,75 @@ public function test_key_source_test_is_critical_when_the_keyring_is_broken(): v | |||||||||
| $this->assertSame( 'critical', $result['status'] ); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * The broken keyring describes itself with a translated string. | ||||||||||
| * | ||||||||||
| * @runInSeparateProcess | ||||||||||
| * @preserveGlobalState disabled | ||||||||||
| */ | ||||||||||
| public function test_key_source_test_is_critical_when_the_keyring_is_broken_on_a_translated_site(): void { | ||||||||||
| $GLOBALS['wp_secrets_dropin_broken'] = true; | ||||||||||
|
|
||||||||||
| add_filter( | ||||||||||
| 'gettext', | ||||||||||
| static function ( $translation, $text ) { | ||||||||||
| return 'broken secrets.php drop-in' === $text ? 'defektes secrets.php-Drop-in' : $translation; | ||||||||||
| }, | ||||||||||
| 10, | ||||||||||
| 2 | ||||||||||
| ); | ||||||||||
|
|
||||||||||
| $result = wp_secrets_site_health_test_key_source(); | ||||||||||
|
|
||||||||||
| $this->assertSame( 'critical', $result['status'] ); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * @runInSeparateProcess | ||||||||||
| * @preserveGlobalState disabled | ||||||||||
| */ | ||||||||||
|
Comment on lines
+154
to
+157
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This docblock has no test under it; the next one already carries both annotations.
Suggested change
|
||||||||||
| /** | ||||||||||
| * A provider from a secrets.php drop-in does not use the default keyring. | ||||||||||
| * | ||||||||||
| * @runInSeparateProcess | ||||||||||
| * @preserveGlobalState disabled | ||||||||||
| */ | ||||||||||
| public function test_key_source_test_is_good_when_a_dropin_replaces_the_provider(): void { | ||||||||||
| $provider = $this->createMock( WP_Secrets_Provider::class ); | ||||||||||
| $provider->method( 'get_label' )->willReturn( 'Example Vault' ); | ||||||||||
|
|
||||||||||
| $GLOBALS['wp_secrets_provider'] = $provider; | ||||||||||
|
|
||||||||||
| $result = wp_secrets_site_health_test_key_source(); | ||||||||||
|
|
||||||||||
| $this->assertSame( 'good', $result['status'] ); | ||||||||||
| $this->assertStringContainsString( 'Example Vault', $result['description'] ); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * @runInSeparateProcess | ||||||||||
| * @preserveGlobalState disabled | ||||||||||
| */ | ||||||||||
| public function test_undecryptable_test_is_critical_when_the_secrets_cannot_be_listed(): void { | ||||||||||
| $GLOBALS['wp_secrets_dropin_broken'] = true; | ||||||||||
|
|
||||||||||
| $result = wp_secrets_site_health_test_undecryptable(); | ||||||||||
|
|
||||||||||
| $this->assertSame( 'critical', $result['status'] ); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * @runInSeparateProcess | ||||||||||
| * @preserveGlobalState disabled | ||||||||||
| */ | ||||||||||
| public function test_needs_rotation_test_is_recommended_when_the_secrets_cannot_be_listed(): void { | ||||||||||
| $GLOBALS['wp_secrets_dropin_broken'] = true; | ||||||||||
|
|
||||||||||
| $result = wp_secrets_site_health_test_needs_rotation(); | ||||||||||
|
|
||||||||||
| $this->assertSame( 'recommended', $result['status'] ); | ||||||||||
| } | ||||||||||
|
|
||||||||||
| public function test_undecryptable_test_is_good_when_nothing_is_broken(): void { | ||||||||||
| wp_set_secret( 'myplugin/api-key', 'value' ); | ||||||||||
|
|
||||||||||
|
|
||||||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only the default keyring reads
wp-config.php. A keyring from a drop-in (a KMS, say) reaches this branch when it was installed without re-wrapping the root key, or when its key service is down. In both cases this message sends the site owner to constants that didn't change, and the keyring's own error is dropped. Details and a test are in the review summary.