fix(security): 安全问题,数字验证码增加参数校验避免伪造绕过

This commit is contained in:
冷冷 committed 2024-08-16 15:28:04 +08:00
1 parent 4118d91756
commit f2921c2102
1 file changed
+9 -4
@@ -1,5 +1,6 @@
package com.pig4cloud.pigx.auth.endpoint;
import cn.hutool.core.lang.Validator;
import com.anji.captcha.model.vo.CaptchaVO;
import com.anji.captcha.service.CaptchaService;
import com.pig4cloud.pigx.common.core.constant.CacheConstants;
@@ -46,6 +47,12 @@ public class ImageCodeEndpoint {
ArithmeticCaptcha captcha = new ArithmeticCaptcha(DEFAULT_IMAGE_WIDTH, DEFAULT_IMAGE_HEIGHT);
String result = captcha.text();
// 如果是手机号码,不存储下发验证码
if (Validator.isMobile(randomStr)) {
return;
}
redisTemplate.opsForValue()
.set(CacheConstants.DEFAULT_CODE_KEY + randomStr, result, SecurityConstants.CODE_TIME, TimeUnit.SECONDS);
// 转换流信息写出
@@ -53,8 +60,7 @@ public class ImageCodeEndpoint {
}
/**
* 行为
* 创建滑块图形验证码
* 行为 创建滑块图形验证码
*/
@SneakyThrows
@GetMapping("/create")
@@ -66,8 +72,7 @@ public class ImageCodeEndpoint {
}
/**
* 行为
* 创建滑块图形验证码
* 行为 创建滑块图形验证码
*/
@SneakyThrows
@PostMapping("/check")