fix 修复 前端输入性CVE漏洞 禁止使用代码生成到本地路径

This commit is contained in:
疯狂的狮子Li
2026-05-06 16:21:17 +08:00
parent 4388ccfe00
commit 48c164b7bb
4 changed files with 3 additions and 63 deletions
@@ -172,20 +172,6 @@ public class GenController extends BaseController {
genCode(response, data);
}
/**
* 生成代码(自定义路径)
*
* @param tableId 表ID
* @return 操作结果
*/
@SaCheckPermission("tool:gen:code")
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
@GetMapping("/genCode/{tableId}")
public R<Void> genCode(@PathVariable("tableId") Long tableId) {
genTableService.generatorCode(tableId);
return R.ok();
}
/**
* 同步数据库
*
@@ -92,17 +92,6 @@ public class GenTable extends BaseEntity {
@NotBlank(message = "作者不能为空")
private String functionAuthor;
/**
* 生成代码方式(0zip压缩包 1自定义路径)
*/
private String genType;
/**
* 生成路径(不填默认项目路径)
*/
@TableField(updateStrategy = FieldStrategy.NOT_EMPTY)
private String genPath;
/**
* 主键信息
*/
@@ -341,39 +341,11 @@ public class GenTableServiceImpl implements IGenTableService {
public byte[] downloadCode(Long tableId) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(outputStream);
generatorCode(tableId, zip);
writeCodeToZip(tableId, zip);
IoUtil.close(zip);
return outputStream.toByteArray();
}
/**
* 生成代码(自定义路径)
*
* @param tableId 表名称
*/
@Override
public void generatorCode(Long tableId) {
// 查询表信息
GenTable table = getGenTable(tableId);
// 设置主键列信息
setPkColumn(table);
Dict context = TemplateEngineUtils.buildContext(table);
// 获取模板列表
List<PathNamedTemplate> templates = TemplateEngineUtils.getTemplateList(table.getTplCategory(), table.getDataName());
for (PathNamedTemplate template : templates) {
String pathName = template.getPathName();
try {
String render = template.render(context);
String path = getGenPath(table, pathName);
FileUtils.writeUtf8String(render, path);
} catch (Exception e) {
log.error("渲染模板失败,表名:{},模板:{}", table.getTableName(), pathName, e);
throw new ServiceException("渲染模板失败,表名:" + table.getTableName() + ",模板:" + pathName);
}
}
}
/**
* 同步数据库
*
@@ -437,7 +409,7 @@ public class GenTableServiceImpl implements IGenTableService {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(outputStream);
for (String tableId : tableIds) {
generatorCode(Long.parseLong(tableId), zip);
writeCodeToZip(Long.parseLong(tableId), zip);
}
IoUtil.close(zip);
return outputStream.toByteArray();
@@ -449,7 +421,7 @@ public class GenTableServiceImpl implements IGenTableService {
* @param tableId 业务表主键
* @param zip 代码压缩输出流
*/
private void generatorCode(Long tableId, ZipOutputStream zip) {
private void writeCodeToZip(Long tableId, ZipOutputStream zip) {
RenderContext rc = buildRenderContext(tableId);
GenTable table = rc.table();
for (PathNamedTemplate template : rc.templates()) {
@@ -105,13 +105,6 @@ public interface IGenTableService {
*/
byte[] downloadCode(Long tableId);
/**
* 生成代码(自定义路径)
*
* @param tableId 表名称
*/
void generatorCode(Long tableId);
/**
* 同步数据库
*