Repository navigation
Commit 5744bc5
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-d223f7449a821 parent d655404 commit 5744bc5
55 files changed
Lines changed: 9433 additions & 1 deletion
File tree
- src
- wp-admin/includes
- wp-includes
- secrets
- tests
- phpstan
- phpunit
- includes
- secrets
- tests
- secrets
- user
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
10 | 13 | | |
11 | 14 | | |
12 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
732 | 732 | | |
733 | 733 | | |
734 | 734 | | |
| 735 | + | |
735 | 736 | | |
736 | 737 | | |
737 | 738 | | |
| |||
968 | 969 | | |
969 | 970 | | |
970 | 971 | | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
971 | 985 | | |
972 | 986 | | |
973 | 987 | | |
| |||
0 commit comments