Audit and harden an AI-authored webhook secret check for case sensitivity and constant-time comparison.
An AI assistant wrote this webhook secret verifier. Happy-path tests pass, but our security reviewer flagged two flaws: it ignores case (weakening token entropy) and uses === (vulnerable to timing attacks). Fix verifyWebhook to be case-sensitive and constant-time without external libraries.
true.whsec_abc vs whsec_AbC) returns false.false safely..toLowerCase() and uses a bitwise XOR (^) constant-time loop..toLowerCase() folds base64/mixed-case token characters, expectedSecret isn't even null-checked, and === short-circuits on the first mismatched character.mismatch |= reqSecret.charCodeAt(i) ^ expectedSecret.charCodeAt(i) across every index 0..length - 1 and return mismatch === 0.Ready to run test suite
Edit the code above and press Cmd/Ctrl + Enter or click Run Tests.