Skip to main content
Module 5 · Lesson 4 of 419/42 in the course~16 min
Module lessons (4/4)

Timing Side-Channels & Constant-Time Compare

Lesson preview6 hands-on exercises readyApplication & Web Security · Module 5 — Applied Cryptography in Browser & Node

Extract an 8-character secret via an early-exit comparison oracle, then implement branch-free XOR constant-time byte comparison.

What you'll learn in this lesson

  • Explain why early-exit === string comparison leaks secret prefix matches through microsecond timing variance.
  • Crack an 8-character secret against a leaky timing oracle in O(N * |alphabet|) steps instead of brute force.
  • Implement XOR accumulation constant-time equality and blind even secret lengths using Double-HMAC comparison.

Overview

Normal string equality (===) stops at the very first differing character. While great for UI speed, short-circuit equality checking bearer tokens, webhook HMACs, or password reset keys creates an adaptive timing side-channel: each correct prefix byte stretches execution by another loop iteration, letting attackers guess secrets character by character!

Walk through the exploit mechanic and three layers of defense:

Sections covered in this lesson

  1. 11. Early-Exit Oracles vs Branch-Free Constant-Time Checks
  2. 22. Interactive Explorer: Early-Exit Timing Oracle
  3. 33. Progressive Labs: Warm-Up → Attack → Defend → Harden
  4. 44. Checkpoints & Code Review
Pro Lesson · Module 5 — Applied Cryptography in Browser & Node

Unlock "Timing Side-Channels & Constant-Time Compare" and the full Application & Web Security curriculum

Extract an 8-character secret via an early-exit comparison oracle, then implement branch-free XOR constant-time byte comparison.

Unlock all 6 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in Application & Web Security plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.