Skip to content

Commit 8164aeb

Browse files
committed
Merge remote-tracking branch 'origin/master' into pr/519
2 parents 89b0395 + b673581 commit 8164aeb

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/signature-algorithms.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,17 @@ export class HmacSha1 implements SignatureAlgorithm {
144144
verifier.update(material);
145145
const res = verifier.digest("base64");
146146

147-
return res === signatureValue;
147+
// Use constant-time comparison to prevent timing attacks (CWE-208)
148+
// See: https://github.com/node-saml/xml-crypto/issues/522
149+
try {
150+
return crypto.timingSafeEqual(
151+
Buffer.from(res, "base64"),
152+
Buffer.from(signatureValue, "base64"),
153+
);
154+
} catch (e) {
155+
// timingSafeEqual throws if buffer lengths don't match
156+
return false;
157+
}
148158
},
149159
);
150160

0 commit comments

Comments
 (0)