Skip to content

Commit

Permalink
use IPs additionally to prints in UGC
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Nov 19, 2017
1 parent 09230d4 commit e973838
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions modules/security/src/main/GarbageCollector.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,33 @@ final class GarbageCollector(

private def apply(user: User, ip: IpAddress, email: EmailAddress): Funit =
userSpy(user) flatMap { spy =>
val others = spy.usersSharingFingerprint.toList
.sortBy(-_.createdAt.getSeconds)
.takeWhile(_.createdAt.isAfter(DateTime.now minusDays 3))
.take(5)
(others.size > 2 && others.forall(closedSB)) ?? {
badOtherAccounts(spy.usersSharingFingerprint).orElse {
badOtherAccounts(spy.usersSharingIp)
} ?? { others =>
isBadIp(ip).map {
_ ?? {
val ipBan = spy.usersSharingIp.forall { u =>
closedSB(u) || !u.seenAt.exists(DateTime.now.minusMonths(2).isBefore)
isBadAccount(u) || !u.seenAt.exists(DateTime.now.minusMonths(2).isBefore)
}
collect(user, email, others, ipBan)
}
}
}
}

private def badOtherAccounts(accounts: Set[User]): Option[List[User]] = {
val others = accounts.toList
.sortBy(-_.createdAt.getSeconds)
.takeWhile(_.createdAt.isAfter(DateTime.now minusDays 3))
.take(5)
(others.size > 2 && others.forall(isBadAccount)) option others
}

private def isBadIp(ip: IpAddress): Fu[Boolean] =
if (firewall blocksIp ip) fuccess(true)
else ipIntel(ip).map { 75 < _ }

private def closedSB(user: User) =
private def isBadAccount(user: User) =
(user.troll || user.engine) && !user.enabled

private val emailSuffixes = "yandex.ru yandex.com mailfa.com"
Expand Down

0 comments on commit e973838

Please sign in to comment.