Blog

Your API Keys Stay in Plain Text: The Secrets API Was Pulled from WordPress 7.2

· 10 min read
An open database drawer full of cards showing key icons, with one key card arcing over to a second drawer; beside them, an unfinished vault door stands inside scaffolding

WordPress 7.2 was going to change how every site stores its API keys. A new Secrets API would have encrypted them, tracked them and given hosts a way to keep them out of the database entirely. It made it into the betas and got a full developer note on November 11. Six days later it was pulled. WordPress 7.2 ships on December 8 without it. Your Stripe, SMTP, Mailchimp, reCAPTCHA and AI provider keys will sit where they’ve always been: in plain text in your database, readable by anyone or anything that gets a copy of it. Here’s what was planned, why it was pulled, and what that means for site owners, agencies, plugin developers and hosts.

Where your keys live today

WordPress has no built-in place for a credential. When you paste an API key into a plugin’s settings page, the plugin almost always saves it with update_option(), the same function it uses for “show the banner: yes.” It lands in the wp_options table as plain text, often inside a serialized array with the rest of the plugin’s settings.

That means every copy of your database is also a copy of your keys:

  • every backup, on your host, in your backup plugin’s cloud storage, or on someone’s laptop
  • every staging and local copy, and every site cloned for a developer
  • every SQL export sent to a freelancer or a support desk
  • every database dump an attacker pulls through a SQL injection bug

It also means any code running on the site can read every key, and so can any administrator who knows where to look. None of this is the plugin authors’ fault. As the proposal put it, writing the key to the options table “is the only available path.” Some plugins encrypt their own credentials, each in its own way, which means each one is a separate thing to audit.

This mattered less when a site held a reCAPTCHA secret and a newsletter key. It matters more now. AI integrations put model-provider keys on ordinary sites, and those keys are billed by use. A leaked newsletter key means spam. A leaked AI key can mean someone else’s workload on your credit card.

What 7.2 was going to change

The Secrets API was proposed on August 25 and landed during the 7.2 betas. The design, from the November 11 developer note:

  • Encryption at rest. Secrets were encrypted with libsodium (XChaCha20-Poly1305) before being stored. A database copy alone would no longer reveal the keys.
  • A new key in wp-config.php. The encryption depended on a new WP_SECRETS_KEY constant. New installs would have generated one with the salts. Existing sites would have added it, with Site Health providing the line to copy.
  • Rotation. Saving a new value kept the previous one, so you could switch a credential without downtime, then retire the old version.
  • Masked values. A secret printed to a log, a debug dump or JSON showed as [secret:my-plugin/api-key], not the key. Only an explicit reveal() call returned the value.
  • Migration help. Plugins could move an existing option into a secret, and core would flag it for rotation, “since the old value has already been through your backups.”
  • Host integration. A secrets.php drop-in let a host keep the encryption key in a key management service, store the encrypted records outside the database, or hand everything to an external secret manager.
  • Visibility. Site Health would have reported missing keys, secrets that couldn’t be decrypted, and credentials due for rotation. For the first time you could ask a site which credentials it holds.

Why it was pulled

The revert went into core on November 17 (changeset 65538). The commit message gives two reasons:

  • Design questions. Feedback on the developer note asked whether writing secrets belongs in the same API as reading secrets a host provides. Those are different jobs, and getting the split wrong would be hard to undo once thousands of plugins depend on it.
  • A missing permission check. Review found that the new manage_secrets and manage_network_secrets capabilities weren’t checked when secrets were set.

Rather than rework the API weeks before release, core removed it “to allow more time for the API to mature before it ships in a future release.” There’s no target version yet. I confirmed it’s gone from the 7.2 branch: there’s no secrets code, and wp-config-sample.php has no WP_SECRETS_KEY.

I think that was the right call. A storage API is one of the few things in WordPress that has to be right the first time. Every plugin that adopts it, and every encrypted value it writes, depends on its design for years. Pulling it late is frustrating. Shipping a flawed design and living with it would be worse.

What encryption would and wouldn’t have fixed

This is worth understanding, because it tells you what to do while you wait. The planned design encrypted secrets in the database with a key stored in wp-config.php. That protects against anything that gets the database without the files:

  • a leaked or stolen database backup
  • a SQL export shared with the wrong person
  • a SQL injection bug that dumps tables but can’t read files

It doesn’t protect against anything that can run code on the site, or read wp-config.php as well as the database. A backdoored plugin, a remote code execution bug like the WP Rocket one being exploited right now, or a full-site backup that includes both files and database. The Rank Math PRO backdoor went straight for every secret the web server could reach, and no at-rest encryption stops that. Only the host-managed option, where the key never sits on the server, would have raised that bar.

So the Secrets API was never going to make keys safe. It was going to make database copies safe, which is where most key leaks happen. That part you can do something about today.

How this affects everyone

Site owners

Nothing changes on December 8, and that’s the point: your keys stay in plain text in the database for at least one more release. If you were waiting for WordPress to handle this, it won’t yet. The steps below are yours to take.

Agencies and freelancers

You probably hold more database copies than anyone: staging sites, local clones, migration exports, old backups of client sites you no longer manage. Each one holds that client’s live payment, email and AI keys. Treat them like the credentials they contain. Delete what you don’t need, and never send a production database to anyone without thinking about what’s inside it.

Plugin developers

Don’t build on wp_set_secret(). It doesn’t exist in 7.2, and the next version may look different. If you added it behind a function_exists() check during the betas, that code is dead and harmless, but remove it so nobody assumes it works. Meanwhile:

  • Let users define keys as constants in wp-config.php, and read the constant before the option. That keeps keys out of the database and its backups.
  • Never print a key back into a settings field. Show the last four characters and a “replace” button.
  • Don’t log full keys, request headers or API responses that echo them.
  • Check manage_options (or stricter) and a nonce on every save, and don’t expose keys through REST, AJAX or abilities.

The revert itself carries the lesson: a credential store whose writes weren’t permission-checked was caught in core review. Check your own.

Hosts

The secrets.php drop-in that would have let you plug in a key management service isn’t loaded in 7.2. If you built one during the betas, it does nothing now. The design discussion is open, and the question that stopped it, how host-provided secrets relate to secrets a site writes itself, is one hosts are best placed to answer.

What to do now

1. Find out what keys your site holds

Run this in phpMyAdmin or with wp db query (change wp_ if your table prefix is different):

SELECT option_name, LENGTH(option_value) AS size
FROM wp_options
WHERE option_name REGEXP 'key|secret|token|api|pass|auth|license'
  AND option_name NOT LIKE '%transient%'
ORDER BY option_name;

Many plugins keep keys inside one big settings option, so names won’t catch everything. Search the values for well-known key formats too:

SELECT option_name
FROM wp_options
WHERE option_value LIKE '%sk\_live\_%'   -- Stripe secret keys
   OR option_value LIKE '%rk\_live\_%'   -- Stripe restricted keys
   OR option_value LIKE '%sk-%'          -- OpenAI, Anthropic and others
   OR option_value LIKE '%SG.%'          -- SendGrid
   OR option_value LIKE '%xkeysib-%';    -- Brevo

The sk- and SG. patterns will return some false matches. That’s fine: you’re making a list, not running a scanner. Write down each key, what service it belongs to, and which plugin uses it.

2. Shrink what each key can do

This helps most, and costs nothing. At each provider:

  • Use restricted or scoped keys where the provider offers them. A form that takes payments doesn’t need a key that can issue refunds or read your customer list.
  • Set spending limits and usage alerts on AI provider keys.
  • Give each site its own key. One shared key across ten client sites means one leak is ten.
  • Delete keys for services you no longer use. The plugin may be gone, but its option often isn’t.

3. Move keys out of the database where you can

Many payment, SMTP, backup and AI plugins document a constant you can define in wp-config.php instead of entering the key in their settings. Check each plugin’s documentation. A key in wp-config.php still sits in plain text, but in a file, not in every database export. Then delete the old value from the settings, and rotate the key, since the old one has already been through your backups.

4. Treat database copies as credentials

Encrypt backups where your backup tool supports it, and limit who can download them. Delete old staging and local copies. When a developer needs a copy, give them one with the keys removed, or use test keys on staging. Most payment and email providers offer them.

5. Rotate after anything that touches the database

If a backup leaks, a developer leaves, a plugin you run turns out to be backdoored, or you clean up after any break-in, rotate every key on your list, not just the WordPress passwords. A cleaned site with the same Stripe key is still exposed.

6. Keep keys out of shell history

If you set keys with WP-CLI, a command like wp option update my_plugin_key sk_live_... leaves the key in your shell history and, on shared servers, briefly in the process list. Use the plugin’s settings screen or a wp-config.php constant instead.

What to watch for

The Secrets API will come back, probably in a different shape. When it does, the questions to ask are the ones that pulled it: who can write a secret, and how host-managed secrets fit in. When it ships, the most useful thing it’ll give you isn’t the encryption. It’s finally being able to ask your site which credentials it holds and when they last changed. Until then, that list is the one from step 1, and you’ll have to keep it yourself.

The bigger lesson

Every plugin that asks for an API key is asking you to trust it with access to another service, often one that can spend your money or send email as you. That trust doesn’t end at the plugin’s code. It extends to every backup, export and staging copy of your database, for as long as that key works. It’s part of what a plugin has to earn its place: not just what it does, but what it asks you to hand over, and where it keeps it.

Sources