3 ms·
Yes, it matters - timing attacks could absolutely work against an indexed column in a database. The trick I've used for this is to have tokens that look like t
by simonw 5y ago
Yes, it matters - timing attacks could absolutely work against an indexed column in a database.
The trick I've used for this is to have tokens that look like this:
"234523:7a561002f780e23853bdfbd89ae79bf2"
Then you have database entries like this:
id = 234523
token = 7a561002f780e23853bdfbd89ae79bf2
When a token comes in you use the bit before the : to look up the database record by its indexed ID, then perform a safe comparison between the rest of the token and the value you retrieved from the database.
- bpicolo 5y agoSerious question - what makes the database serialization not vulnerable to timing attacks in the same vein? I wouldn't expect those to be purely constant time implementations.
- simonw 5y agoYou do the final comparison outside of the database after retrieving the stored value - I use the Python secrets.compare_digest() function for that.
- zaroth 5y agoI’d rather store an HMAC of the token. That way you’re hashing the user input, which sanitizes it. It also protects against timing attacks.* And most importantly it protects against credentials leaking. Even insiders who can read a token from the database can’t use it to authenticate, because the app logic expects a pre-image of that value. *HMAC resists timing attacks because the attacker can no longer control the bit pattern on either side of the equality check.
- juancampa 5y agoSo basically passwords
- ezekg 5y agoTokens are basically passwords, so yes.
- tptacek 5y agoNot really, no.
- ezekg 5y agoYou wrote that entire blog post ... and you disagree that tokens are essentially passwords? Why so?
- tptacek 5y agoYou might find the answer in the post.
- ezekg 5y agoI read the entire post. Still not following. Perhaps just a misunderstanding between us?
- jbverschoor 5y agoSame here. These are all examples of the same things. If you get your hands on the secret, you can do anything. The only thing the post explains that there is a difference between checking a secret with the database vs message validation, also based on a secret. But for both, if you have the secret, you're doomed. Expiration / immediate revocation when doing message validation is more difficult than having a distributed cache, which supports key eviction/expiry/removal. Also, an asymmetric solution has similar problems: if you get the private key from the client, you're doomed. So it does protect the server part, but if people have access there, you're even more doomed. But at least it'll be easier to identify who had a security leak./