🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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 ==?

  1. A.It is shorter
  2. B.It compares in constant time, so timing doesn't reveal how many characters matched
  3. C.== doesn't work on strings
  4. 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 →