获取短信验证码接口爆破测试漏洞问题
获取短信验证码接口,存在无限制向不同手机号发验证码,可能会出现攻击者遍历全国手机号批量发送验证码,存在安全隐患。
解决方案:
对发送验证码端做一个IP速率限制
//同一个IP地址限制次数
String ipAddress = IPUtils.getIpAddress(request);
Integer timeCount = (Integer) redisCacheService.get("IP"+ipAddress+phone);
if (ObjectUtils.isNull(timeCount)){
redisCacheService.setKey("IP"+ipAddress+phone,"1",1L,TimeUnit.MINUTES);
//每小时只能发送五次
Long sendNumLimit = redisCacheService.boundValueOps("IP" + ipAddress+phone, 1);
if (sendNumLimit ==1){
//设置一小时后过期
redisCacheService.expire("IP"+ipAddress+phone,1L,TimeUnit.HOURS);
}
if (sendNumLimit>5){
throw new BusinessException(ErrorStatus.ILLEGAL_ARGUMENT,"当前用户IP地址请求超出限制,请稍后再试");
}
}else if (timeCount>=1){
throw new BusinessException(ErrorStatus.ILLEGAL_ARGUMENT,"请勿重复发送,请一分钟后重试");
}
|