-
-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Derive Eq, Hash for CsrfToken
#107
Comments
These traits are intentionally omitted from the types that wrap secrets in order to prevent timing side channels. To safely use CSRF tokens and other secrets as lookups in data structures, I recommend creating another wrapper type that only performs comparisons on a collision- and preimage-resistant hash (e.g., SHA-2) of the underlying secret and never compares the raw secrets themselves. In theory we could implement the traits above directly on |
Using a dedicated crate (like sha2, as mentioned) to hash and compare seems reasonable, and wouldn't require much effort on my end. Timing attacks are always one thing I never think about — which is why it's best to leave it to others! Thank you for the quick response. I'll close this, as I won't have a ton of time to put together a proper pull request. |
Can
#[derive(PartialEq, Eq, Hash)]
be added toCsrfToken
? This would allow usage withinHashSet
andBTreeSet
, which would let me keep track of outstanding tokens. The only alternative I can think of is to use aVec
, but that's O(n), which obviously isn't ideal.The text was updated successfully, but these errors were encountered: