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

Integrity with HMAC vs Broken Prefix Hashing

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

Exploit canonical boundary collisions in naive SHA-256 concatenation, then sign and verify payloads properly with HMAC-SHA256.

What you'll learn in this lesson

  • Explain why concatenating SHA-256(secret + fields) exposes canonical boundary collisions and length-extension attacks.
  • Exploit an unframed concatenation hash to collide 'admin_readonly' + 'billing' with 'admin' + '_readonlybilling'.
  • Sign and verify canonical tuples via crypto.subtle HMAC-SHA256 and enforce timestamp replay windows on webhooks.

Overview

A raw hash function (SHA-256) creates fingerprints of unkeyed bytes — it was never meant to work as sha256(secret + fieldA + fieldB) for message authentication. Two distinct flaws hit raw concatenated MACs: missing delimiters let values slide across field boundaries, and Merkle-Damgard hash internals permit length-extension attacks without…

Study how unframed SHA-256 fails and how HMAC fixes both structural and cryptographic bugs:

Sections covered in this lesson

  1. 11. Boundary Collisions, Length Extensions & Canonical HMAC
  2. 22. Interactive Explorer: HMAC vs Prefix Hash & Replay
  3. 33. Progressive Labs: Warm-Up → Attack → Defend → Harden
  4. 44. Checkpoints & Code Review
Pro Lesson · Module 5 — Applied Cryptography in Browser & Node

Unlock "Integrity with HMAC vs Broken Prefix Hashing" and the full Application & Web Security curriculum

Exploit canonical boundary collisions in naive SHA-256 concatenation, then sign and verify payloads properly with HMAC-SHA256.

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.