Skip to content

Commit

Permalink
revert http basic auth
Browse files Browse the repository at this point in the history
it can't be fast and secure.
  • Loading branch information
ornicar committed Feb 7, 2018
1 parent 89f8b47 commit 618186c
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 30 deletions.
2 changes: 1 addition & 1 deletion modules/security/src/main/Env.scala
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ final class Env(
scheduler.once(30 seconds)(tor.refresh(_ => funit))
scheduler.effect(TorRefreshDelay, "Refresh Tor exit nodes")(tor.refresh(firewall.unblockIps))

lazy val api = new SecurityApi(storeColl, firewall, geoIP, authenticator, emailAddressValidator, asyncCache)
lazy val api = new SecurityApi(storeColl, firewall, geoIP, authenticator, emailAddressValidator)

lazy val csrfRequestHandler = new CSRFRequestHandler(NetDomain)

Expand Down
28 changes: 2 additions & 26 deletions modules/security/src/main/SecurityApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ final class SecurityApi(
firewall: Firewall,
geoIP: GeoIP,
authenticator: lila.user.Authenticator,
emailValidator: EmailAddressValidator,
asyncCache: lila.memo.AsyncCache.Builder
emailValidator: EmailAddressValidator
) {

val AccessUri = "access_uri"
Expand Down Expand Up @@ -77,7 +76,7 @@ final class SecurityApi(
}
}
}
} // orElse BasicAuth(req).map2 { (u: User) => FingerprintedUser(u, false) }
}
}

def locatedOpenSessions(userId: User.ID, nb: Int): Fu[List[LocatedSession]] =
Expand All @@ -95,29 +94,6 @@ final class SecurityApi(

def reqSessionId(req: RequestHeader) = req.session get "sessionId"

private object BasicAuth {

private type Username = String

private val cache = asyncCache.multi[(Username, User.ClearPassword), Boolean](
name = "security.basic_auth",
f = {
case (username, password) => authenticator.authenticateByUsername(username, password).map(_.isDefined)
},
expireAfter = _.ExpireAfterWrite(2 minutes)
)

def apply(req: RequestHeader): Fu[Option[User]] = {
req.headers get "Authorization" flatMap lila.common.String.base64.decode map (_.split(":", 2))
} ?? {
case Array(username, password) =>
cache.get(username -> User.ClearPassword(password)) flatMap {
_ ?? UserRepo.named(username)
}
case _ => fuccess(none)
}
}

def userIdsSharingIp = userIdsSharingField("ip") _

def recentByIpExists(ip: IpAddress): Fu[Boolean] = Store recentByIpExists ip
Expand Down
3 changes: 0 additions & 3 deletions modules/user/src/main/Authenticator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ final class Authenticator(
def authenticateById(id: User.ID, password: ClearPassword): Fu[Option[User]] =
loginCandidateById(id) map { _ flatMap { _(password) } }

def authenticateByUsername(username: String, password: ClearPassword): Fu[Option[User]] =
authenticateById(User normalize username, password)

def authenticateByEmail(email: EmailAddress, password: ClearPassword): Fu[Option[User]] =
loginCandidateByEmail(email) map { _ flatMap { _(password) } }

Expand Down

0 comments on commit 618186c

Please sign in to comment.