Question

I created a plugin, and used the add_admin_menu() to add some page for users to put their Api keys and secret word. My page content is just a form to collect those data the users puts in, now my question is apart from sending data to database as to always retrieve them there, is there another place i can store those keys and secret word?

Was it helpful?

Solution

Not really, if you want it to be updatable via a form then the only alternatives are these which I do not recommend:

  • Files, very bad for security, easily stolen
  • Object Cache, while rarely done and esoteric by most peoples standards, if you have an object cache installed such as memcached or redis, and an object drop-in, you could use this. However, this is somewhat ephemeral, and not fully persistent, as well as requiring the installation of server software. This also runs the risk of the user using a caching plugin that caches to the disk, posing a security risk
  • Secure vaults, requires the set up and configuration of additional software on the server, e.g. https://www.vaultproject.io/, as well as a client library. Additionally you might need to store authentication details which lands you back where you started. Few users will be able to use this

I would store it in the database. If the app key and secret are stolen they can be revoked, and a new key/secret saved.

For completeness, there are 2 other alternatives that cannot be updated or set via the browser, both require server level access however to change and set, providing greater security:

  • wp-config.php constants, e.g. define( 'CHRIS_PLUGIN_APP_KEY','XXXXXX' );, this has greater security but can be difficult for users to set
  • Environment variables, define them at the system level not the WordPress level, $_ENV['CHRIS_APP_KEY'], this is potentially the most secure option

Neither of those options can be changed from WordPress however.

Warning: Some people might take this as a cue to try and modify wp-config.php in code, this is extremely bad practice and can easily kill a website, a lot of hosts prevent modifications to that file, and users can place wp-config.php in strange places or do odd things with it.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top