🌐 HMAC in Action: APIs, Webhooks & Blockchain
Explore how HMAC secures API requests, webhooks, and blockchain transactions
Your Progress
0 / 5 completed🛡️ Real-World Security
Let's see how HMAC defends against real attacks in the wild. Understanding these threats will make you a security-conscious blockchain developer!
🎮 Interactive Attack Scenarios
Select an attack type to see how HMAC protects against it:
Attacker captures valid request and sends it again
Alice sends: "Transfer $100 to Bob" with valid HMAC
Attacker intercepts and replays the same request 10 times
❌ Without protection: Transfer happens 10 times! $1000 stolen.
✅ With timestamp: Server rejects old requests (>5 min). Attack fails!
🏢 Major Platforms Using HMAC
World's largest crypto exchange
• 5-second timestamp window
• Signature in request header
Leading US crypto platform
• Includes request body + timestamp
• CB-ACCESS-SIGN header
Amazon Web Services
• HMAC-SHA256 based signing
• Signs entire request (headers + body)
Payment processing platform
• Stripe-Signature header
• Prevents webhook spoofing
🔐 Best Practices Checklist
SHA-256 or SHA-3, never MD5 or SHA-1
Minimum 32 bytes (256 bits) of cryptographically secure random data
Reject requests older than 5 minutes to prevent replay attacks
HMAC protects integrity, HTTPS protects confidentiality
Use environment variables, never hardcode in source
Prevents timing attacks when verifying signatures
Change API secrets every 90 days or after suspected compromise
Block IPs after repeated invalid signatures (brute force protection)
🚨 Common Mistakes to Avoid
Never send the secret key in requests! Only the signature should travel over the network.
Without timestamp checks, attackers can replay old valid requests indefinitely.
Client and server must build the signature payload EXACTLY the same way (same order, formatting).
HMAC proves integrity, but without HTTPS, requests can still be read by eavesdroppers.
Never log secrets in application logs, error messages, or debugging output.
🎯 HMAC vs Other Auth Methods
| Method | Security | Performance | Use Case |
|---|---|---|---|
| HMAC | ✅ Very High | ⚡ Fast | API authentication |
| API Keys Only | ⚠️ Medium | ⚡ Very Fast | Read-only APIs |
| JWT Tokens | ✅ High | ⚡ Fast | User sessions |
| OAuth 2.0 | ✅ High | 🐌 Slower | Third-party access |
| Digital Signatures | ✅ Very High | 🐌 Slow | Blockchain transactions |