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?
1 Answer
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.
-
These leaves me with no other choice than using the database, as these other mentioned alternatives are less secured or requires much work, besides i want the keys to be updated once the form is submitted.– chrisCommented Sep 15, 2020 at 12:34
-
I need to study more on $_ENV variable but it seems the user must be updating or adding the keys each time he logins in to the site? Or are $_env permanent like a database storage too?– chrisCommented Sep 15, 2020 at 12:39
-
Environment variables are set at a server level, not a site level, not all hosts will allow this, and it isn't something that can be changed from the browser or PHP. It's not set at the application level, and would probably require someone to SSH into the server to set it. If you SSH into a server and run
TEST=1
then runecho "${TEST}"
then you're doing something similar to environment variables but restricted just to your session. Technically, it's an operating level feature, likePATH
on windows– Tom J Nowell ♦Commented Sep 15, 2020 at 14:24 -
Thanks @Tom J Like you said earlier is not something i can use in this function.– chrisCommented Sep 15, 2020 at 17:55