Skip to content

Commit 5744bc5

Browse files
committed
Security: Introduce the Secrets API.
Credentials such as API keys and tokens are usually stored as plaintext options, so anyone with a database dump or backup can read them. The Secrets API gives plugins and core a place to store them encrypted instead, using `wp_set_secret()`, `wp_get_secret()`, `wp_delete_secret()` and related functions. Each secret keeps its previous version, so a credential can be rotated without breaking the code that reads it. By default, secrets are encrypted with libsodium and stored in the options table. The encryption key never goes in the database: it comes from a `WP_SECRETS_KEY` constant in `wp-config.php`, or is derived from the `LOGGED_IN_KEY` and `LOGGED_IN_SALT` constants when that is not defined. Hosts can use a different method by adding a `wp-content/secrets.php` drop-in, which loads just before must-use plugins, in the same way `object-cache.php` replaces the object cache. A drop-in can hand all storage to an external secrets manager, or replace only where secrets are stored or only where the encryption key comes from, such as a key management service. If a drop-in is broken, every Secrets API call returns a `WP_Error` rather than falling back to the default method, so a misconfigured host shows up as an error rather than as secrets that appear not to exist. Conformance test suites are included for drop-in authors. Also adds the `manage_secrets` capability, granted to administrators through `populate_roles_720()` and `upgrade_720()`, the `manage_network_secrets` meta capability for super admins, and Site Health tests for the Secrets API. This provides the encrypted storage requested in #64789, so the Connectors screen's API keys can move off plaintext options in a follow-up. The admin screen is deferred to 7.3, and the WP-CLI commands stay in the feature plugin. Props ericmann, westonruter, mindctrl, audrasjb, whyisjake. Fixes #66187. See #64789. git-svn-id: https://develop.svn.wordpress.org/trunk@64337 602fd350-edb4-49c9-b593-d223f7449a82
1 parent d655404 commit 5744bc5

55 files changed

Lines changed: 9433 additions & 1 deletion

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎src/wp-admin/includes/class-wp-site-health.php‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
* @since 5.2.0
88
*/
99

10+
11+
require_once __DIR__ . '/secrets-site-health.php';
12+
1013
#[AllowDynamicProperties]
1114
class WP_Site_Health {
1215
private static $instance = null;

‎src/wp-admin/includes/schema.php‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,7 @@ function populate_roles() {
732732
populate_roles_270();
733733
populate_roles_280();
734734
populate_roles_300();
735+
populate_roles_720();
735736

736737
// Save the updated roles to the database.
737738
if ( $original_use_db ) {
@@ -968,6 +969,19 @@ function populate_roles_300() {
968969
}
969970
}
970971

972+
/**
973+
* Create and modify WordPress roles for WordPress 7.2.
974+
*
975+
* @since 7.2.0
976+
*/
977+
function populate_roles_720(): void {
978+
$role = get_role( 'administrator' );
979+
980+
if ( ! empty( $role ) ) {
981+
$role->add_cap( 'manage_secrets' );
982+
}
983+
}
984+
971985
if ( ! function_exists( 'install_network' ) ) :
972986
/**
973987
* Install Network.

0 commit comments

Comments
 (0)