Reading the tutorial here: https://github.com/defuse/php-encryption/blob/master/docs/Tutorial.md (scenario #2)
It is advised to store the encryption key in a session variable. I was wondering, is it safer to store the key in a cookie variable instead?
My assumption:
- $_SESSION is stored in the server
- $_COOKIE is stored in the client's device (browser)
Threat model:
- Against employees of hosting provider snooping data
- Against hackers (they will likely attack the server instead of a user's device)
Update:
Notes for clarification in comments for @SteffenUllrich. Below are the exact quotes in the tutorial.
SteffenUllrich: "Where the encrypted data are located..."
Alice wants to host Dave's web application, including its database, on her server
SteffenUllrich: "recommendation regarding storing the key in the session.."
save the Key object somewhere safe (like temporary memory-backed session storage)
$_SESSION
but talks about some session storage with the important features of temporary and memory-backed. As far as I know there are different implementations possible for the session object, including cookies or database. While the last one is stored on the server like you assume it is definitely not memory-backed and maybe not even temporary. It is definitely not a good idea to keep the key together with the encrypted data on disk.