Skip to content

Commit

Permalink
make sure input-as-buffer is same length as expected buffer before co…
Browse files Browse the repository at this point in the history
…mparing. fixes #40
  • Loading branch information
natevw committed Feb 17, 2022
1 parent 2e896ce commit ea03dd5
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ exports.unsign = function(input, secret){
var tentativeValue = input.slice(0, input.lastIndexOf('.')),
expectedInput = exports.sign(tentativeValue, secret),
expectedBuffer = Buffer.from(expectedInput),
inputBuffer = Buffer.alloc(expectedBuffer.length);

inputBuffer.write(input);
return crypto.timingSafeEqual(expectedBuffer, inputBuffer) ? tentativeValue : false;
inputBuffer = Buffer.from(input);
return (
expectedBuffer.length === inputBuffer.length &&
crypto.timingSafeEqual(expectedBuffer, inputBuffer)
) ? tentativeValue : false;
};

0 comments on commit ea03dd5

Please sign in to comment.