mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-14 06:09:03 +08:00
fix(security): 安全问题,数字验证码增加参数校验避免伪造绕过
This commit is contained in:
1 parent
4ddf8c34e2
commit
3ed430a92e
1 file changed
+11
-6
@@ -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;
|
||||
@@ -8,8 +9,6 @@ import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import com.pig4cloud.pigx.common.core.util.SpringContextHolder;
|
||||
import io.springboot.captcha.ArithmeticCaptcha;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
@@ -18,6 +17,8 @@ import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
@@ -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")
|
||||
|
||||
Reference in new issue
Block a user