For a webapp which stores encrypted files, a public key is used to encrypt random key/ivs, which are used to encrypt the stored files. The private key, used for decryption, is guarded with a password that must be supplied by the user to access the files (the nature of the system is such that only one user has/needs the ability to access the files unencrypted).
In order to prevent the user from needing to type the private key password on every page load, it should be stored (say, for 10 minutes). The question is, where/how to store it?
Putting it in a cookie is analogous to the user typing it on every request, so that's an advantage. But, then someone with access to their computer could look at their browser's data and see/retrieve the key in plain text. Plus it's up to the browser to expire it on time (which it could choose not to do)
On the other hand, it could be stored in session data on the server. This gives better control over its expiration, and means the key isn't flying all over the internet with every request (obviously, this is all over https, but still). But that means storing the password, the key, and the data all on the same machine (albeit temporarily), which doesn't seem that great either.
Is one of these objectively better? Is there a better alternative than either?