-
Notifications
You must be signed in to change notification settings - Fork 30k
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
doc: add caveats and example to crypto.timingSafeEqual #41837
base: main
Are you sure you want to change the base?
Conversation
`crypto.timingSafeEqual` has a number of caveats to its use that are worth mentioning. While surrounding code isn't strictly the responsibility of `crypto.timingSafeEqual`, documenting these pitfalls may help avoid some very common errors.
@nodejs/crypto |
Welcome @lostfictions and thank you for the contribution!
Do you have an example use case that potentially passes inputs to |
secretBuffer.write(secret); | ||
|
||
return timingSafeEqual(inputBuffer, secretBuffer) && | ||
inputBuffer.length === Buffer.byteLength(secret); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, operations such as Buffer.byteLength(secret)
are generally not timing-safe.
Fair enough! Maybe this is all extraneous and
I actually saw this is in the wild in a package with 240,000 downloads per week: Admittedly maybe the bigger issue here is "never use basic auth"? |
#41507 recently added documentation about an error case for
crypto.timingSafeEqual
, but even with that addition I think there are a few extra caveats totimingSafeEqual
's use that are worth mentioning. I've tried to be as clear as possible in this addition without going outside the scope of documentation for a single function (ie. into the realm of broader crypto best practices). I've also added a short example for the function.