12

I'm looking to use a few APIs and many come with keys, secret keys and passwords required to work. Where in WordPress can you store that information? Assuming anyone can hack your DB is there anyway for WordPress to make saving that information more secure? Also, consider the ability to change these keys ever so often so I would need to update the keys on an options page.

UPDATE

2 Answers 2

10

There is no absolutely safe way to store such information permanently.
You have two options to increase security a little bit:

  1. Use the options table and encrypt the data

    Use a strong encryption method, and bind it to either:

    • your password when you want to use the API call only when you are logged in, or
    • a secret key stored in your wp-config.php – then an attacker needs both, the PHP code and the database
  2. Store the access information outside of WordPress

    If you are using a system for automatic deployment, for example based on Composer and wpstarter, you have probably some kind of deployment server like Envoyer that creates a file with important configuration variables that is stored outside of the site server’s document root.
    Then you can use the deployment server’s backend instead of the WordPress backend to change these data.

Both options are not completely safe. You still have to monitor the actual API usage to detect unintended activities. Make sure there is a log that cannot be compromised from someone with full access to your website.

3
  • Is there a way to integrate something like Azure Key Vault into WP? Commented May 1, 2020 at 14:28
  • @PoorInRichfield: Yes to AZ Key Vault. It’s a REST API to retrieve keys. To not require any key management, and assuming hosting in Azure, you can use system-managed identities so only the calling server can access the Key Vault. If you’re hosting on-prem, the keys to access KV will also need to be secured. Commented Nov 8, 2022 at 8:24
  • And don’t forget to encrypt your connections! Commented Nov 8, 2022 at 8:30
6

The answer is NO. If your DB can be spied on, your code probably can be as well so even if you encrypt data it can be decrypted.

If you are going to store sensitive data there are no low level solution to help you with it and you just need to make your whole application secure to make the question of storage irrelevant.

I actually ran into a requirement to encrypt data so if the app security is breached and you get access only to the DB you can not use that data, but in real life you are more likely to be hacked at the wordpress level than the DB level.

2
  • DB encryption is also to prevent theft of data caused by disk re-use at the data centre. It is possible to run forensics on newly provisioned disk storage and retrieve a previous customer’s data. Commented Nov 8, 2022 at 8:26
  • +1 to moving the problem, and not tackling the problem solely in WP. Provision a separate dedicated secrets store product and store them in there Commented Nov 8, 2022 at 8:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.