Bug 17286 – A function for comparing two digests securely
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-03-29T20:27:03Z
Last change time
2018-01-05T13:28:05Z
Assigned to
No Owner
Creator
Jack Stouffer
Comments
Comment #0 by jack — 2017-03-29T20:27:03Z
Given two strings A and B, using std.algorithm.equal to compare them leaves your web application open to timing attacks because it has a short circuit, i.e. it returns false on the first inequality.
The attack comes from allowing attacker to brute force you HMAC key. See this article for more information and why Java gets it wrong: https://codahale.com/a-lesson-in-timing-attacks/
The solution is to have a string comparison that will always be constant time given two strings of the same length.