You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 7516662
Browse filesBrowse the repository at this point in the historyBrowse files
Security: Improve Secrets API tests and inline documentation.
Brings the Secrets API tests in line with the PHPUnit test-writing guidelines and tidies the inline documentation.
Documentation:
* Remove references to the feature plugin, its proposal and its decision records, including in the `_doing_it_wrong()` notice for unnamespaced names.
* Add `@global` annotations for the drop-in globals, rewrite the Site Health test summaries as statements, and correct the `WP_Secret::__debugInfo()` description, which also applies to `print_r()`.
* Use `/* */` for multi-line comments, "ID" rather than "id", and `@subpackage Secrets` in the test files.
Tests:
* Add `@ticket 66187` to each test class, a summary and `@covers` annotation to each test, and order annotations consistently.
* Move `@covers` targets in the conformance suites from the interfaces to the implementations under test, declared on the concrete test classes, so coverage is attributed to the code that runs. The base suites no longer filter coverage for extending classes.
* Add a unique failure message to every assertion within each test, including a new `$message` parameter for `assertRecordSlotDecryptsTo()`.
* Assert the result of every setup write. This exposed two separate-process tests that passed without testing anything because no usable key was available; both now define a test key and check the specific error returned.
* Remove duplicated tests, rename tests whose names did not match what they check, and name single-use data providers after their test.
* Add tests for a store that cannot list its secrets, for every `WP_SECRETS_ERROR_*` constant being pinned, and for a valid but different `WP_SECRETS_KEY`.
* Strengthen assertions that could pass without checking their stated behavior, such as missing error codes, counts and the salt-derived key.
* Use the `ms-required` and `multisite` groups with `skipWithoutMultisite()` for multisite-only tests, and `skipWithMultisite()` for the `ms-excluded` test, instead of skipping with `markTestSkipped()`.
Developed in #15481.
Follow-up to r64337, r64344, r64345, r64674.
See #66187, #66353.
git-svn-id: https://develop.svn.wordpress.org/trunk@65272 602fd350-edb4-49c9-b593-d223f7449a82
Copy file name to clipboardExpand all lines: src/wp-includes/secrets.php
+37-50Lines changed: 37 additions & 50 deletions
Original file line number
Diff line number
Diff line change
@@ -50,7 +50,7 @@
50
50
/**
51
51
* A caller passed an argument this API cannot act on.
52
52
*
53
-
* An unrecognized version constant, or an invalid scope, slot, or site id.
53
+
* An unrecognized version constant, or an invalid scope, slot, or site ID.
54
54
*
55
55
* Distinct from the codes above in cause rather than in severity: those describe
56
56
* a runtime condition a correct caller can still hit (a name that failed
@@ -86,9 +86,9 @@
86
86
*
87
87
* Distinct from WP_SECRETS_ERROR_RECORD_MALFORMED so that an operator, or Site
88
88
* Health, can tell a corrupt record apart from one written by a newer version of
89
-
* this plugin than is currently active. See
90
-
* docs/decisions/0006-record-format-v2-not-read-compatible.md. The upgrade path for a future v2 is not
91
-
* designed, so an unrecognized version is rejected outright rather than guessed at.
89
+
* WordPress than is currently running. The upgrade path for a future record format
90
+
* is not designed, so an unrecognized version is rejected outright rather than
91
+
* guessed at.
92
92
*
93
93
* @since 7.2.0
94
94
*/
@@ -184,15 +184,19 @@ function wp_secrets_memzero( &$value ): void {
184
184
$alias =& $value;
185
185
sodium_memzero( $alias );
186
186
} catch ( \Throwable$e ) {
187
-
// A value this function doesn't exclusively own (a shared,
188
-
// copy-on-write buffer) can legitimately refuse. The unconditional
189
-
// reassignment below still runs regardless of what happened here.
187
+
/*
188
+
* A value this function doesn't exclusively own (a shared,
189
+
* copy-on-write buffer) can legitimately refuse. The unconditional
190
+
* reassignment below still runs regardless of what happened here.
191
+
*/
190
192
unset( $e );
191
193
}
192
194
}
193
195
194
-
// Reached on every path, including sodium_memzero() success (it leaves the
195
-
// variable null, not an empty string) so callers see one consistent contract.
196
+
/*
197
+
* Reached on every path, including sodium_memzero() success (it leaves the
198
+
* variable null, not an empty string) so callers see one consistent contract.
199
+
*/
196
200
$value = '';
197
201
}
198
202
@@ -208,9 +212,9 @@ function wp_secrets_memzero( &$value ): void {
208
212
* plugin that can run PHP can read any secret, namespaced or not.
209
213
*
210
214
* An unnamespaced name ('secret-name', no '/') is accepted, but reports through
211
-
* _doing_it_wrong(). It exists for one reason: code written against the earlier
212
-
* prototype used a flat keyspace, and refusing those names outright would mean
213
-
* every such call site has to be rewritten before it can be ported at all.
215
+
* _doing_it_wrong(). It exists for one reason: existing code may already use a flat
216
+
* keyspace, and refusing those names outright would mean every such call site has
217
+
* to be rewritten before it can be ported at all.
214
218
* Accepting them keeps that migration incremental. Nothing else should use one.
215
219
* Two plugins that both choose 'api-key' collide silently, which is a real problem
216
220
* even though it is not a security one.
@@ -268,7 +272,7 @@ function wp_secrets_validate_name( string $name ) {
268
272
__FUNCTION__,
269
273
sprintf(
270
274
/* translators: %s: The unnamespaced secret name. */
271
-
__( 'The secret name "%s" has no namespace. Namespaced names ("plugin-slug/secret-name") group secrets by owner so that listings and admin screens can be organized; unnamespaced names are supported only so that code written against the Displace prototype can be ported incrementally.' ),
275
+
__( 'The secret name "%s" has no namespace. Namespaced names ("plugin-slug/secret-name") group secrets by owner so that listings and admin screens can be organized; unnamespaced names are supported only so that existing code using flat names can be ported incrementally.' ),
272
276
$name
273
277
),
274
278
'7.2.0'
@@ -301,10 +305,10 @@ function wp_secrets_validate_name( string $name ) {
301
305
/**
302
306
* Returns the active secret store.
303
307
*
304
-
* No filter is applied here, or anywhere on the retrieval path. See
305
-
* docs/spec/extension-points.md. A secrets.php drop-in overrides the store by setting
306
-
* $GLOBALS['wp_secrets_store'] to an instance before this is first called, and
307
-
* that global is checked here directly, not through a hook.
308
+
* No filter is applied here, or anywhere on the retrieval path. A secrets.php
309
+
* drop-in overrides the store by setting $GLOBALS['wp_secrets_store'] to an
310
+
* instance before this is first called, and that global is checked here directly,
311
+
* not through a hook.
308
312
*
309
313
* If the global was set but is not a valid WP_Secrets_Store, or if the drop-in
310
314
* itself failed to load cleanly, this returns WP_Secrets_Broken_Store rather than
@@ -314,6 +318,9 @@ function wp_secrets_validate_name( string $name ) {
314
318
*
315
319
* @since 7.2.0
316
320
*
321
+
* @global bool $wp_secrets_dropin_broken Whether the secrets.php drop-in failed to load cleanly.
322
+
* @global WP_Secrets_Store $wp_secrets_store Optional. Store override set by the drop-in.
functionwp_list_secrets( string$namespace = '' ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.namespaceFound -- $namespace is the parameter name the proposal specifies.
530
+
functionwp_list_secrets( string$namespace = '' ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.namespaceFound -- $namespace is the public parameter name; renaming it would break named-argument callers.
0 commit comments