← Quiz: CSRF and CORS: all 10 questions
Quiz: CSRF and CORS · Question 4 of 10
Why does the CSRF demo use hmac.comparedigest instead of ==?
Why does the CSRF demo use hmac.compare_digest instead of ==?
- A.It is shorter
- B.It compares in constant time, so timing doesn't reveal how many characters matched
- C.== doesn't work on strings
- D.It hashes the password
Answer & explanation
Correct answer: It compares in constant time, so timing doesn't reveal how many characters matched
A normal comparison can stop at the first mismatch; measuring that time can help an attacker guess secrets.
Can you get the rest right without peeking?
Take the timed Quiz: CSRF and CORS quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →