Skip to content

Commit

Permalink
fix timing side channel in StringToken (closes lichess-org/tactics#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed May 4, 2019
1 parent 3d40c3a commit 4b41ce0
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion modules/security/src/main/StringToken.scala
Expand Up @@ -2,6 +2,7 @@ package lila.security

import com.roundeights.hasher.Algo
import lila.common.String.base64
import org.mindrot.BCrypt

import StringToken.ValueChecker

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

0 comments on commit 4b41ce0

Please sign in to comment.