20260726:在次调严控IP攻击

This commit is contained in:
zhugongping 2026-07-26 10:00:09 +08:00
parent ced3257a79
commit be2e868ef5
2 changed files with 5 additions and 4 deletions

View File

@ -142,8 +142,8 @@ sip:
# SIP安全防护配置 # SIP安全防护配置
security: security:
enabled: true # 是否启用安全防护 enabled: true # 是否启用安全防护
rate-limit: 10 # 每分钟最大请求数(生产环境更严格) rate-limit: 5 # 每分钟最大请求数(生产环境更严格)
block-threshold: 20 # 触发封禁的请求次数 block-threshold: 10 # 触发封禁的请求次数
block-duration: 10080 # 封禁时长(分钟)一个星期 block-duration: 10080 # 封禁时长(分钟)一个星期
# 日志配置 # 日志配置

View File

@ -62,13 +62,14 @@ public class SipSecurityServiceImpl implements ISipSecurityService {
return true; return true;
} }
// 2. 记录请求计数(1分钟窗口) // 2. 记录请求计数(2分钟窗口)
// 2分钟5次请求之后就拒绝,10次请求后就封禁
String countKey = COUNT_PREFIX + ip; String countKey = COUNT_PREFIX + ip;
long count = redisCache.incr(countKey, 1); long count = redisCache.incr(countKey, 1);
// 首次访问设置过期时间 // 首次访问设置过期时间
if (count == 1) { if (count == 1) {
redisCache.expire(countKey, 60, TimeUnit.SECONDS); redisCache.expire(countKey, 120, TimeUnit.SECONDS);
} }
// 3. 检查是否超过速率限制 // 3. 检查是否超过速率限制