Skip to content

Commit

Permalink
let lichobile pass the UA test
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Jan 18, 2025
1 parent c4b592f commit 434ef97
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions modules/security/src/main/UserAgentParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ object UserAgentParser:
def isSuspicious(req: RequestHeader): Boolean = HTTPRequest.userAgent(req).forall(isSuspicious)

def isSuspicious(ua: UA): Boolean =
val str = ua.value.take(200).toLowerCase
str.lengthIs < 30 || isMacOsEdge(str) || !looksNormal(str)
!isLichobile(ua) && {
val str = ua.value.take(200).toLowerCase
str.lengthIs < 30 || isMacOsEdge(str) || !popularBrowser(str)
}

private def looksNormal(ua: String) =
private def popularBrowser(ua: String) =
val sections = ua.split(' ')
sections.exists: s =>
isRecentChrome(s) || isLastWindows8Chrome(s) || isRecentFirefox(s) || isRecentSafari(s)
Expand All @@ -62,3 +64,5 @@ object UserAgentParser:
private def isLastWindows8Chrome(s: String) = s.startsWith("chrome/109.")

private def isMacOsEdge(ua: String) = ua.contains("macintosh") && ua.contains("edg/")

private def isLichobile(ua: UA) = ua.value.contains("Lichobile/")

0 comments on commit 434ef97

Please sign in to comment.