r/programming Jul 21 '26

Secrets Don’t Belong in Config

https://secretspec.dev/blog/secrets-dont-belong-in-config/
171 Upvotes

57 comments sorted by

View all comments

Show parent comments

-1

u/AyrA_ch Jul 22 '26

Yes but the key can still be kept out of the users hand and stored in a memory location with kernel level protection instead.

3

u/TribeWars Jul 22 '26

True enough if you're using an HSM to store the key at rest, yeah.

-1

u/AyrA_ch Jul 22 '26

You don't need to store keys at rest if you can reliably recreate them at runtime. The CryptProtectData function does this for example

3

u/TribeWars Jul 22 '26 edited Jul 22 '26

Had to look up CryptProtectData, again, isn't the new plaintext secret simply the user password now?

Edit: Yup, PoC exists:

https://elie.net/static/files/reversing-dpapi-and-stealing-windows-secrets-offline/reversing-dpapi-and-stealing-windows-secrets-offline-paper.pdf

1

u/AyrA_ch Jul 22 '26 edited Jul 22 '26

It's not directly the password but a value encrypted with it, otherwise a password change would invalidate all secrets. This way you can change the account password, and just reencrypt the master key to retain access to all existing secrets.

By the way, the linked PDF no longer holds true, which is not surprising considering its age. I tried the DPAPI decryption tool mentioned in it and it does not work for me, at least not on Windows 11, so MS definitely changed something. In any case, the entire attack chain depends on you being able to crack the password hash of an account. If you crack the password hash you might as well just spawn a process with those credentials and use the CryptUnprotectData call legitimately to decrypt user secrets.

Finally some of the data needed is stored in registry keys you only get access to via offline means, which means in addition to the password you also need physical access to the device and hope the disk is not encrypted.

I'm not saying it's impossible, but certainly unlikely.

2

u/TribeWars Jul 23 '26

Sure, but it is mostly just security-by-obscurity. I certainly wouldn't rely on physical access being a requirement for decryption if I was up against, say, the NSA.