Skip to content

fix: eval in portableTimingSafeEqual #227

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

Merged
merged 8 commits into from
Oct 15, 2019
22 changes: 14 additions & 8 deletions modules/material-management/src/cryptographic_material.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,20 @@ const timingSafeEqual: (a: Uint8Array, b: Uint8Array) => boolean = (function ()
/* https://codahale.com/a-lesson-in-timing-attacks/ */
function portableTimingSafeEqual (a: Uint8Array, b: Uint8Array) {
/* It is *possible* that a runtime could optimize this constant time function.
* Adding `eval` should prevent the optimization, but this is no grantee.
* If you copy this function for your own use, make sure to educate yourself.
* Side channel attacks are pernicious and subtle.
*/
eval('') // eslint-disable-line no-eval
/* Check for early return (Postcondition) UNTESTED: Size is well-know information.
* and does not leak information about contents.
*/
* Adding `eval` could prevent the optimization, but this is no guarantee.
* The eval below is commented out
* because if a browser is using a Content Security Policy with `'unsafe-eval'`
* it would fail on this eval.
* The value in attempting to ensure that this function is not optimized
* is not worth the cost of making customers allow `'unsafe-eval'`.
* If you want to copy this function for your own use,
* please review the timing-attack link above.
* Side channel attacks are pernicious and subtle.
*/
// eval('') // eslint-disable-line no-eval
/* Check for early return (Postcondition) UNTESTED: Size is well-know information
* and does not leak information about contents.
*/
if (a.byteLength !== b.byteLength) return false

let diff = 0
Expand Down