Comment on How to store user's access tokens/API keys without hashing them?
MajorHavoc@lemmy.world 1 year agoNeat. I can help with some of these concepts:
- WSSE is just a reimplantation of Basic Auth, but it has a dramatically worse security posture today, than Basic Auth. WSSE is complex and deprectaed. Basic Auth is not wonderful, but is simple and is still being patched.
- On that note, Basic Auth is almost certainly what you want here.
- Don’t use cleartext for any of this (obviously). It need HTTPS or it’ll get owned immediately.
- Don’t do an extra encryption step inside your HTTPS connection. HTTPS isn’t perfect security, but if a job doesn’t call for OAuth and token rotation, it also probably also doesn’t call for a needless extra layer of encryption on the wire.
- Do encrypt your data at rest.
- None of your source code should be doing any kind of encrytion.
- Encryption on the wire should be via HTTPS.
- Encrytion in storage (at rest) should be via a database or disk drive setting.
- There’s no benefit to encrytping data that has already been encrypted, and there’s real risks of accidentally ruining the protection of the original encryption. But mostly, additional encryption just makes life hard for your ops team while adding zero security value.
You can protect your Basic Auth password simply by storing it in cleartext where it is needed with reasonable protections
(This is again assuming your use case is actually okay for not having OAuth. If it’s health data, suck it up and do real OAuth, obviously.)
Reasonable protections for your Basic Auth passwords:
- Make sure nobody except your administration team can read the file where it is stored.
- Have separate basic Auth passwords for every service and client. No one wants one compromised password compromising everything. This happens all the time and it’s not pretty.
- Don’t ship it around your network for fun. If you have access to AWS secrets, Hashi Vault or Azure Secrets, put it there and check it out as runtime. Otherwise, just put it where it needs to be and don’t try to be clever about it.
- Don’t check passwords into source control. It ends up being another avenue to accidentally share them.
In summary:
- Use basic Auth.
- write the password in plain text in a correctly secured file exactly where it’s needed.
- for the love of all that’s holy, don’t try to use WSSE.
- use HTTPS.
Happy sailing!
pe1uca@lemmy.pe1uca.dev 1 year ago
Thanks for all the information and advises!
So in theory basic auth is enough when sent through HTTPS, right?
If this is the case then the user would need to handle their password and my API can keep storing just the hash.
In another comment JWT was suggested, maybe this could also be a solution?
I’m thinking the user can worry about generating and signing the token and we could only be storing the public key , which requires less strictness when handling it, this way we can validate the token has been signed by who we expect and the user will worry about the private key.
MajorHavoc@lemmy.world 1 year ago
Yes. Don’t put nuclear weapons, health data or huge sums of money behind it, but basic Auth has been doing a fine job for a lot of things for a long time, and HTTPS is a complete solution (until the next time it gets owned).
Yep. The hard part is securely delivering the generated secret to them. And making sure that, the shorter and less random that secret is, the more often it gets replaced. For a lot of not-too-sensitive use cases, a phone call and a long random secret will do the job.
JWT is a fantastic solution, and probably the first thing you want to upgrade to if your use case needs more than Basic Auth.
That makes sense. Note that many popular JWT libraries will do a lot of that for you.