As long as t + s
is sufficient to cover any delays in responses introduced by a DDoS style attack, where s
is the number of seconds.
That is, hitting a service listener that calls the above in order to encourage stuffWhoseTimingCantBeLeaked()
to take longer than s
could reveal to the attacker how long, on average, stuffWhoseTimingCantBeLeaked()
takes to execute, once the t + s
barrier is broken.
To mitigate this, you could mask this extra time by detecting when your function takes longer:
let t = timeRightNow()
let s = 1
let waitTime = t + s
let message = stuffWhoseTimingCantBeLeaked()
let executeTime = timeRightNow() - t
if timeRightNow() > waitTime
waitUntilTime(timeRightNow() + executeTime * csprng(2,1)) # Random wait of between 1 and 2 times the original execution time (integer)
else
waitUntilTime(waitTime)
send message
Note though, with enough requests it might be possible to get an average that will even out, leaking the time taken to execute stuffWhoseTimingCantBeLeaked()
.
With higher values of s
, the risk can be lowered further, at the expense of performance. You could also introduce detection of whether your web service is requested repeatedly from a certain user or IP address and then rate limit the connection.