hard10-15 min18% solve rate
The Security Hole in String Comparison
This authentication check has a vulnerability that could expose your secrets.
SecurityNode.js
The Code
This code passed code review and works in development. But it has a bug that will cause problems in production.
auth.js
1const crypto = require('crypto');23function verifySignature(token, secret) {4const [header, payload, signature] = token.split('.');56// Recreate the signature7const data = `${header}.${payload}`;8const expectedSignature = crypto9.createHmac('sha256', secret)10.update(data)11.digest('base64url');1213// Compare signatures14if (signature === expectedSignature) {15return true;16}1718return false;19}2021// This JWT verification has a security vulnerability.22// An attacker could potentially forge valid tokens.23// What's the issue?
Need a Hint?
0 of 3 revealedHint 1 locked
Hint 2 locked
Hint 3 locked
Ready for the Solution?
Enter your email to get the full solution with explanation, the fix, and why this bug is so common.