fix(security): 修复网安扫描相关严重/高危/中危漏洞并加固学生密码重置
关闭工作流 SpEL 命令执行与社团活动 SQL 注入,补齐越权、调试接口、登录喷洒和异常回显等问题;学生密码改为随机临时密码,Web/移动端支持复制。 Constraint: 流程发起/办理接口保持仅登录校验,避免影响请假审批 Rejected: 开启验证码 | Web/移动端登录页均未实现,开启会导致无法登录 Confidence: high Scope-risk: broad Not-tested: 生产环境与社团社长/指导老师视角 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
845c7fd942
commit
da8d332fac
79 files changed
+1156
-547
No files matched your search
@@ -1,5 +1,6 @@
|
||||
package org.dromara.web.controller;
|
||||
|
||||
import org.dromara.common.web.handler.GlobalExceptionHandler;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.common.core.domain.R;
|
||||
@@ -178,14 +179,14 @@ public class CasController {
|
||||
return R.fail(ue.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("处理 CAS profile 失败", e);
|
||||
return R.fail("处理 CAS profile 失败: " + e.getMessage());
|
||||
return R.fail("处理 CAS profile 失败: " + GlobalExceptionHandler.safeMessage(e.getMessage()));
|
||||
}
|
||||
} else {
|
||||
return R.fail("无法解析 CAS access_token");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("请求 CAS accessToken 失败", e);
|
||||
return R.fail("请求 CAS accessToken 失败: " + e.getMessage());
|
||||
return R.fail("请求 CAS accessToken 失败: " + GlobalExceptionHandler.safeMessage(e.getMessage()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,7 +73,7 @@ public class UserActionListener implements SaTokenListener {
|
||||
SpringUtils.context().publishEvent(logininforEvent);
|
||||
// 更新登录信息
|
||||
loginService.recordLoginInfo((Long) loginParameter.getExtra(LoginHelper.USER_KEY), ip);
|
||||
log.info("user doLogin, userId:{}, token:{}", loginId, tokenValue);
|
||||
log.info("user doLogin, userId:{}", loginId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,7 +85,7 @@ public class UserActionListener implements SaTokenListener {
|
||||
TenantHelper.dynamic(tenantId, () -> {
|
||||
RedisUtils.deleteObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue);
|
||||
});
|
||||
log.info("user doLogout, userId:{}, token:{}", loginId, tokenValue);
|
||||
log.info("user doLogout, userId:{}", loginId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,7 +97,7 @@ public class UserActionListener implements SaTokenListener {
|
||||
TenantHelper.dynamic(tenantId, () -> {
|
||||
RedisUtils.deleteObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue);
|
||||
});
|
||||
log.info("user doKickout, userId:{}, token:{}", loginId, tokenValue);
|
||||
log.info("user doKickout, userId:{}", loginId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,7 +109,7 @@ public class UserActionListener implements SaTokenListener {
|
||||
TenantHelper.dynamic(tenantId, () -> {
|
||||
RedisUtils.deleteObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue);
|
||||
});
|
||||
log.info("user doReplaced, userId:{}, token:{}", loginId, tokenValue);
|
||||
log.info("user doReplaced, userId:{}", loginId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -56,6 +56,9 @@ public class SysLoginService {
|
||||
@Value("${user.password.lockTime}")
|
||||
private Integer lockTime;
|
||||
|
||||
@Value("${user.password.ipMaxRetryCount:30}")
|
||||
private Integer ipMaxRetryCount;
|
||||
|
||||
private final ISysTenantService tenantService;
|
||||
private final ISysPermissionService permissionService;
|
||||
private final ISysSocialService sysSocialService;
|
||||
@@ -200,7 +203,23 @@ public class SysLoginService {
|
||||
throw new UserException(loginType.getRetryLimitExceed(), maxRetryCount, lockTime);
|
||||
}
|
||||
|
||||
// 按公网来源 IP 统计失败次数,防止对大量账号逐个试密码;校园内网 / 本机 IP 不计
|
||||
String clientIp = ServletUtils.getClientIP();
|
||||
String ipErrorKey = null;
|
||||
if (ipMaxRetryCount > 0 && StringUtils.isNotBlank(clientIp) && isPublicClientIp(clientIp)) {
|
||||
ipErrorKey = CacheConstants.PWD_ERR_CNT_KEY + "ip:" + clientIp;
|
||||
int ipErrorNumber = ObjectUtil.defaultIfNull(RedisUtils.getCacheObject(ipErrorKey), 0);
|
||||
if (ipErrorNumber >= ipMaxRetryCount) {
|
||||
recordLogininfor(tenantId, username, loginFail, MessageUtils.message("user.ip.retry.limit.exceed", lockTime));
|
||||
throw new UserException("user.ip.retry.limit.exceed", lockTime);
|
||||
}
|
||||
}
|
||||
|
||||
if (supplier.get()) {
|
||||
if (ipErrorKey != null) {
|
||||
int ipErrorNumber = ObjectUtil.defaultIfNull(RedisUtils.getCacheObject(ipErrorKey), 0);
|
||||
RedisUtils.setCacheObject(ipErrorKey, ipErrorNumber + 1, Duration.ofMinutes(lockTime));
|
||||
}
|
||||
// 错误次数递增
|
||||
errorNumber++;
|
||||
RedisUtils.setCacheObject(errorKey, errorNumber, Duration.ofMinutes(lockTime));
|
||||
@@ -219,6 +238,23 @@ public class SysLoginService {
|
||||
RedisUtils.deleteObject(errorKey);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为需要计入失败锁定的公网 IP。本机、内网 IPv4/IPv6 不计;无法解析时按公网处理,且不得抛异常阻断登录。
|
||||
*/
|
||||
private boolean isPublicClientIp(String ip) {
|
||||
try {
|
||||
if (NetUtils.isIPv6(ip)) {
|
||||
return !NetUtils.isInnerIPv6(ip);
|
||||
}
|
||||
if (NetUtils.isIPv4(ip)) {
|
||||
return !NetUtils.isInnerIP(ip);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("无法判断登录来源 IP 是否内网: {}", ip);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验租户
|
||||
*
|
||||
|
||||
+4
-2
@@ -64,7 +64,9 @@ public class PasswordAuthStrategy implements IAuthStrategy {
|
||||
}
|
||||
LoginUser loginUser = TenantHelper.dynamic(tenantId, () -> {
|
||||
SysUserVo user = loadUserByUsername(username);
|
||||
loginService.checkLogin(LoginType.PASSWORD, tenantId, username, () -> !BCrypt.checkpw(password, user.getPassword()));
|
||||
// 用户不存在时按密码错误处理,避免通过提示差异枚举账号
|
||||
loginService.checkLogin(LoginType.PASSWORD, tenantId, username,
|
||||
() -> user == null || !BCrypt.checkpw(password, user.getPassword()));
|
||||
// 此处可根据登录用户的数据不同 自行创建 loginUser
|
||||
return loginService.buildLoginUser(user);
|
||||
});
|
||||
@@ -112,7 +114,7 @@ public class PasswordAuthStrategy implements IAuthStrategy {
|
||||
SysUserVo user = userMapper.selectVoOne(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUserName, username));
|
||||
if (ObjectUtil.isNull(user)) {
|
||||
log.info("登录用户:{} 不存在.", username);
|
||||
throw new UserException("user.not.exists", username);
|
||||
return null;
|
||||
} else if (SystemConstants.DISABLE.equals(user.getStatus())) {
|
||||
log.info("登录用户:{} 已被停用.", username);
|
||||
throw new UserException("user.blocked", username);
|
||||
|
||||
@@ -348,7 +348,8 @@ logging:
|
||||
mybatis-plus:
|
||||
configuration:
|
||||
# 生产环境关闭 SQL 日志打印,避免性能影响和敏感信息泄露
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
# 生产禁止将完整 SQL 及参数(身份证号、手机号等)打印到控制台,需排查时在 dev 环境开启
|
||||
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
# 开启驼峰命名转换
|
||||
map-underscore-to-camel-case: true
|
||||
# 开启缓存
|
||||
|
||||
@@ -66,6 +66,8 @@ user:
|
||||
maxRetryCount: 5
|
||||
# 密码锁定时间(默认10分钟)
|
||||
lockTime: 10
|
||||
# 同一公网IP在锁定时间内允许的最大登录失败次数(内网IP不计,0为关闭)
|
||||
ipMaxRetryCount: 30
|
||||
|
||||
# Spring配置
|
||||
spring:
|
||||
@@ -124,10 +126,12 @@ sa-token:
|
||||
# 在多人登录同一账号时,是否共用一个token (为true时所有登录共用一个token, 为false时每次登录新建一个token)
|
||||
is-share: false
|
||||
# jwt秘钥
|
||||
jwt-secret-key: abcdefghijklmnopqrstuvwxyz
|
||||
jwt-secret-key: 23e9ff71db5bbbb1ccd808d2ec35533ec53ee80740b5185adc8ba9bed7897610
|
||||
|
||||
# security配置
|
||||
security:
|
||||
# 允许跨域访问的来源(支持 * 通配子域名与 [*] 通配端口);前端均经 nginx 同源访问 /prod-api,新增域名时在此补充
|
||||
cors-allowed-origins: "http://*.hzdyjsxy.cn:[*],https://*.hzdyjsxy.cn:[*],http://localhost:[*],http://127.0.0.1:[*]"
|
||||
# 排除路径(P0:已下线 Swagger/api-docs,不再加入白名单)
|
||||
excludes:
|
||||
- /*.html
|
||||
@@ -174,7 +178,8 @@ mybatis-plus:
|
||||
typeAliasesPackage: org.dromara.**.domain
|
||||
# 启用SQL日志输出,用于调试数据库插入问题
|
||||
configuration:
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
# 生产禁止将完整 SQL 及参数(身份证号、手机号等)打印到控制台,需排查时在 dev 环境开启
|
||||
# log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
global-config:
|
||||
dbConfig:
|
||||
# 主键类型
|
||||
|
||||
@@ -6,6 +6,7 @@ user.not.exists=对不起, 您的账号:{0} 不存在.
|
||||
user.password.not.match=用户不存在/密码错误
|
||||
user.password.retry.limit.count=密码输入错误{0}次
|
||||
user.password.retry.limit.exceed=密码输入错误{0}次,帐户锁定{1}分钟
|
||||
user.ip.retry.limit.exceed=登录失败次数过多,请{0}分钟后再试
|
||||
user.password.delete=对不起,您的账号:{0} 已被删除
|
||||
user.blocked=对不起,您的账号:{0} 已禁用,请联系管理员
|
||||
role.blocked=角色已封禁,请联系管理员
|
||||
|
||||
@@ -6,6 +6,7 @@ user.not.exists=Sorry, your account: {0} does not exist
|
||||
user.password.not.match=User does not exist/Password error
|
||||
user.password.retry.limit.count=Password input error {0} times
|
||||
user.password.retry.limit.exceed=Password input error {0} times, account locked for {1} minutes
|
||||
user.ip.retry.limit.exceed=Too many failed logins, please try again in {0} minutes
|
||||
user.password.delete=Sorry, your account:{0} has been deleted
|
||||
user.blocked=Sorry, your account: {0} has been disabled. Please contact the administrator
|
||||
role.blocked=Role disabled,please contact administrators
|
||||
|
||||
@@ -6,6 +6,7 @@ user.not.exists=对不起, 您的账号:{0} 不存在.
|
||||
user.password.not.match=用户不存在/密码错误
|
||||
user.password.retry.limit.count=密码输入错误{0}次
|
||||
user.password.retry.limit.exceed=密码输入错误{0}次,帐户锁定{1}分钟
|
||||
user.ip.retry.limit.exceed=登录失败次数过多,请{0}分钟后再试
|
||||
user.password.delete=对不起,您的账号:{0} 已被删除
|
||||
user.blocked=对不起,您的账号:{0} 已禁用,请联系管理员
|
||||
role.blocked=角色已封禁,请联系管理员
|
||||
|
||||
Reference in new issue
Block a user