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:
“wuzhen”andCursor committed 2026-10-26 13:44:51 +08:00
1 parent 845c7fd942
commit da8d332fac
79 files changed
+1156 -547

No files matched your search

@@ -37,4 +37,46 @@ public class MimeTypeUtils {
// pdf
"pdf"};
private static final java.util.Map<String, String> SAFE_CONTENT_TYPES = java.util.Map.ofEntries(
java.util.Map.entry("bmp", IMAGE_BMP),
java.util.Map.entry("gif", IMAGE_GIF),
java.util.Map.entry("jpg", IMAGE_JPEG),
java.util.Map.entry("jpeg", IMAGE_JPEG),
java.util.Map.entry("png", IMAGE_PNG),
java.util.Map.entry("pdf", "application/pdf"),
java.util.Map.entry("txt", "text/plain;charset=UTF-8"),
java.util.Map.entry("doc", "application/msword"),
java.util.Map.entry("docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"),
java.util.Map.entry("xls", "application/vnd.ms-excel"),
java.util.Map.entry("xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"),
java.util.Map.entry("ppt", "application/vnd.ms-powerpoint"),
java.util.Map.entry("pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation"),
java.util.Map.entry("mp4", "video/mp4")
);
/**
* 扩展名是否在上传白名单内
*/
public static boolean isAllowedExtension(String extension) {
if (extension == null || extension.isBlank()) {
return false;
}
for (String allowed : DEFAULT_ALLOWED_EXTENSION) {
if (allowed.equalsIgnoreCase(extension)) {
return true;
}
}
return false;
}
/**
* 按扩展名确定存储时使用的 Content-Type,不信任客户端上报值,防止以 text/html 等类型上传后在浏览器中执行脚本
*/
public static String getSafeContentType(String extension) {
if (extension == null) {
return "application/octet-stream";
}
return SAFE_CONTENT_TYPES.getOrDefault(extension.toLowerCase(), "application/octet-stream");
}
}
@@ -41,7 +41,7 @@ public class MybatisExceptionHandler {
return R.fail(HttpStatus.HTTP_INTERNAL_ERROR, "未找到数据源,请联系管理员确认");
}
log.error("请求地址'{}', Mybatis系统异常", requestURI, e);
return R.fail(HttpStatus.HTTP_INTERNAL_ERROR, message);
return R.fail(HttpStatus.HTTP_INTERNAL_ERROR, "数据处理异常,请稍后重试或联系管理员");
}
}
@@ -6,7 +6,6 @@ import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.common.sse.core.SseEmitterManager;
import org.dromara.common.sse.dto.SseMessageDto;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.http.MediaType;
@@ -14,7 +13,6 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import java.util.List;
/**
* SSE 控制器
@@ -51,32 +49,6 @@ public class SseController implements DisposableBean {
return R.ok();
}
/**
* 向特定用户发送消息
*
* @param userId 目标用户的 ID
* @param msg 要发送的消息内容
*/
@GetMapping(value = "${sse.path}/send")
public R<Void> send(Long userId, String msg) {
SseMessageDto dto = new SseMessageDto();
dto.setUserIds(List.of(userId));
dto.setMessage(msg);
sseEmitterManager.publishMessage(dto);
return R.ok();
}
/**
* 向所有用户发送消息
*
* @param msg 要发送的消息内容
*/
@GetMapping(value = "${sse.path}/sendAll")
public R<Void> send(String msg) {
sseEmitterManager.publishAll(msg);
return R.ok();
}
/**
* 清理资源。此方法目前不执行任何操作,但避免因未实现而导致错误
*/
@@ -1,5 +1,7 @@
package org.dromara.common.web.config;
import java.util.List;
import org.springframework.beans.factory.annotation.Value;
import org.dromara.common.web.handler.GlobalExceptionHandler;
import org.dromara.common.web.interceptor.PlusWebInvokeTimeInterceptor;
import org.springframework.boot.autoconfigure.AutoConfiguration;
@@ -33,11 +35,11 @@ public class ResourcesConfig implements WebMvcConfigurer {
* 跨域配置
*/
@Bean
public CorsFilter corsFilter() {
public CorsFilter corsFilter(@Value("${security.cors-allowed-origins:http://localhost:[*],http://127.0.0.1:[*]}") List<String> allowedOrigins) {
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
// 设置访问源地址
config.addAllowedOriginPattern("*");
// 设置访问源地址(仅允许配置的本校域名,禁止回显任意 Origin)
allowedOrigins.forEach(config::addAllowedOriginPattern);
// 设置访问源请求头
config.addAllowedHeader("*");
// 设置访问源请求方法
@@ -37,6 +37,30 @@ import java.io.IOException;
@RestControllerAdvice
public class GlobalExceptionHandler {
private static final String DEFAULT_ERROR_MESSAGE = "系统繁忙,请稍后重试或联系管理员";
private static final String[] TECHNICAL_MARKERS = {
"###", "sql", "jdbc", "exception", "java.", "javax.", "jakarta.", "org.", "com.", "mapper",
"select ", "insert ", "update ", "delete ", " from ", " where ", "table", "column", "syntax",
"\tat ", "nested", "cause:", "null"
};
/**
* 仅返回业务提示类异常信息,包含 SQL、类名、堆栈等技术细节的信息统一替换为通用提示,避免泄露系统内部结构
*/
public static String safeMessage(String message) {
if (message == null || message.isBlank() || message.length() > 300) {
return DEFAULT_ERROR_MESSAGE;
}
String lower = message.toLowerCase();
for (String marker : TECHNICAL_MARKERS) {
if (lower.contains(marker)) {
return DEFAULT_ERROR_MESSAGE;
}
}
return message;
}
/**
* 请求方式不支持
*/
@@ -55,7 +79,8 @@ public class GlobalExceptionHandler {
public R<Void> handleServiceException(ServiceException e, HttpServletRequest request) {
log.error(e.getMessage());
Integer code = e.getCode();
return ObjectUtil.isNotNull(code) ? R.fail(code, e.getMessage()) : R.fail(e.getMessage());
String message = safeMessage(e.getMessage());
return ObjectUtil.isNotNull(code) ? R.fail(code, message) : R.fail(message);
}
/**
@@ -76,7 +101,7 @@ public class GlobalExceptionHandler {
public R<Void> handleServletException(ServletException e, HttpServletRequest request) {
String requestURI = request.getRequestURI();
log.error("请求地址'{}',发生未知异常.", requestURI, e);
return R.fail(e.getMessage());
return R.fail(DEFAULT_ERROR_MESSAGE);
}
/**
@@ -85,7 +110,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(BaseException.class)
public R<Void> handleBaseException(BaseException e, HttpServletRequest request) {
log.error(e.getMessage());
return R.fail(e.getMessage());
return R.fail(safeMessage(e.getMessage()));
}
/**
@@ -105,7 +130,7 @@ public class GlobalExceptionHandler {
public R<Void> handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e, HttpServletRequest request) {
String requestURI = request.getRequestURI();
log.error("请求参数类型不匹配'{}',发生系统异常.", requestURI);
return R.fail(String.format("请求参数类型不匹配,参数[%s]要求类型为:'%s',但输入值为:'%s'", e.getName(), e.getRequiredType().getName(), e.getValue()));
return R.fail(String.format("请求参数类型不匹配,参数[%s]格式错误", e.getName()));
}
/**
@@ -139,7 +164,7 @@ public class GlobalExceptionHandler {
public R<Void> handleRuntimeException(RuntimeException e, HttpServletRequest request) {
String requestURI = request.getRequestURI();
log.error("请求地址'{}',发生未知异常.", requestURI, e);
return R.fail(e.getMessage());
return R.fail(safeMessage(e.getMessage()));
}
/**
@@ -149,7 +174,7 @@ public class GlobalExceptionHandler {
public R<Void> handleException(Exception e, HttpServletRequest request) {
String requestURI = request.getRequestURI();
log.error("请求地址'{}',发生系统异常.", requestURI, e);
return R.fail(e.getMessage());
return R.fail(DEFAULT_ERROR_MESSAGE);
}
/**
@@ -190,7 +215,7 @@ public class GlobalExceptionHandler {
public R<Void> handleJsonParseException(JsonParseException e, HttpServletRequest request) {
String requestURI = request.getRequestURI();
log.error("请求地址'{}' 发生 JSON 解析异常: {}", requestURI, e.getMessage());
return R.fail(HttpStatus.HTTP_BAD_REQUEST, "请求数据格式错误(JSON 解析失败):" + e.getMessage());
return R.fail(HttpStatus.HTTP_BAD_REQUEST, "请求数据格式错误(JSON 解析失败)");
}
/**
@@ -199,7 +224,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(HttpMessageNotReadableException.class)
public R<Void> handleHttpMessageNotReadableException(HttpMessageNotReadableException e, HttpServletRequest request) {
log.error("请求地址'{}', 参数解析失败: {}", request.getRequestURI(), e.getMessage());
return R.fail(HttpStatus.HTTP_BAD_REQUEST, "请求参数格式错误:" + e.getMostSpecificCause().getMessage());
return R.fail(HttpStatus.HTTP_BAD_REQUEST, "请求参数格式错误");
}
}