doc: add caveats and example to crypto.timingSafeEqual#41837
doc: add caveats and example to crypto.timingSafeEqual#41837lostfictions wants to merge 3 commits intonodejs:mainfrom
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.
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.