SQL报错泄漏(中危)
# 漏洞等级
中危
# 漏洞描述
由于系统后端代码未自定义SQL抛出异常,导致系统中接口请求时,缺少参数和其他原因,引发后端SQL报错,从而直接将SQL报错信息输出;
# 漏洞危害
# 修复建议
后端代码自定义输出异常,禁止将SQL报错信息回显输出
# 修复代码
```java
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ResponseBody;
import java.sql.SQLException;
@ControllerAdvice
public class ExceptionHandler {
private static final Logger log = LoggerFactory.getLogger(ExceptionHandler.class);
@org.springframework.web.bind.annotation.ExceptionHandler({SQLException.class})
@ResponseBody
public ResponseResult<Object> handleNullPointerException(SQLException e) {
log.error("代码错误,sql异常:" + e);
return ResultUtil.error("代码错误,sql异常");
}
}
```