Allow escaped characters in SIP URI user part and authentication username
This commit is contained in:
@ -206,13 +206,10 @@ class Account(val accp: String) {
|
||||
fun checkAuthUser(au: String): Boolean {
|
||||
if (au == "") return true
|
||||
val ud = au.split("@")
|
||||
val userIDRegex = Regex("^([* .!%_`'~]|[+]|[-a-zA-Z0-9]){1,64}\$")
|
||||
val telnoRegex = Regex("^[+]?[0-9]{1,16}\$")
|
||||
if (ud.size == 1) {
|
||||
return userIDRegex.matches(ud[0]) || telnoRegex.matches(ud[0])
|
||||
} else {
|
||||
return (userIDRegex.matches(ud[0]) || telnoRegex.matches(ud[0])) &&
|
||||
Utils.checkDomain(ud[1])
|
||||
return when (ud.size) {
|
||||
1 -> Utils.checkUriUser(au)
|
||||
2 -> Utils.checkUriUser(ud[0]) && Utils.checkDomain(ud[1])
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -161,8 +161,10 @@ object Utils {
|
||||
checkIpV6(bracketedIp.substring(1, bracketedIp.length - 2))
|
||||
}
|
||||
|
||||
private fun checkUriUser(user: String): Boolean {
|
||||
user.forEach { if (!(it.isLetterOrDigit() || "-_.!~*\'()&=+\$,;?/".contains(it))) return false }
|
||||
fun checkUriUser(user: String): Boolean {
|
||||
val escaped = """%(\d|A|B|C|D|E|F|a|b|c|d|e|f){2}""".toRegex()
|
||||
escaped.replace(user, "").forEach {
|
||||
if (!(it.isLetterOrDigit() || "-_.!~*\'()&=+\$,;?/".contains(it))) return false }
|
||||
return user.isNotEmpty() && !checkIpV4(user) && !checkIpV6(user)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user