You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
asyncfunctiontest(){constpayload=Uint8Array.from([0,3,4,2])constkey=awaitjose.JWK.createKey('EC','P-256')constpk=awaitjose.JWK.asKey(key.toJSON())console.log(pk)constsig=awaitjose.JWS.createSign({format: 'compact'},key).update(payload).final()console.log(sig)constres=awaitjose.JWS.createVerify(pk).verify(sig+'12')// APPEND GARBAGE DATA TO SIGNATURE// still get result.console.log(res,res.payload.toString('hex'),Buffer.from(payload).toString('hex'))}test()
The text was updated successfully, but these errors were encountered:
That's because the library doesn't check if the signature length matches the actual digest. You can add checks if you want it to fail, for example in hmac.js, you can update the logic from:
function compare(len, expected, actual) {
len = (len || CONSTANTS.HASHLENGTH[hash]) / 8;
var valid = true;
for (var idx = 0; len > idx; idx++) {
valid = valid && (expected[idx] === actual[idx]);
}
return valid;
}
to
function compare(len, expected, actual) {
len = (len || CONSTANTS.HASHLENGTH[hash]) / 8;
if (expected.length !== actual.length) { // just add a check here
return false;
}
var valid = true;
for (var idx = 0; len > idx; idx++) {
valid = valid && (expected[idx] === actual[idx]);
}
return valid;
}
Am I mistaken, or is this not right?
Affected version: 2.0.0
The text was updated successfully, but these errors were encountered: