Skip to content

Commit 4b41ce0

Browse files
committed
fix timing side channel in StringToken (closes lichess-org/tactics#11)
1 parent 3d40c3a commit 4b41ce0

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

modules/security/src/main/StringToken.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package lila.security
22

33
import com.roundeights.hasher.Algo
44
import lila.common.String.base64
5+
import org.mindrot.BCrypt
56

67
import StringToken.ValueChecker
78

@@ -24,7 +25,7 @@ private[security] final class StringToken[A](
2425
def read(token: String): Fu[Option[A]] = (base64 decode token) ?? {
2526
_ split separator match {
2627
case Array(payloadStr, hashed, checksum) =>
27-
(makeHash(signPayload(payloadStr, hashed)) == checksum) ?? {
28+
BCrypt.bytesEqualSecure(makeHash(signPayload(payloadStr, hashed)).getBytes("utf-8"), checksum.getBytes("utf-8")) ?? {
2829
val payload = serializer read payloadStr
2930
(valueChecker match {
3031
case ValueChecker.Same => hashCurrentValue(payload) map (hashed ==)

0 commit comments

Comments
 (0)