fix(P0②/P1⑥): 对抗审查收口 4 major + minor

对抗审查 workflow(3 lens)揪出并修复:
- [major] AlterTableSqlGuard 移除 ALTER COLUMN TYPE:静态守卫拿不到旧尺寸,无法
  保证扩长(varchar(1)/numeric(1,0) 缩短会截断/溢出存量数据),一律拒;扩长须由
  MetaController 比对旧列长度后再生成
- [major] addAttributes 校验-写分离 + @Transactional + ALTER 失败抛异常:
  杜绝「元数据写了但物理表没加」孤儿(PG 事务性 DDL 一起回滚)
- [major] createEntity 检查 executeCreateSql 返回值 + @Transactional:引擎拒建表
  不再静默成功
- [major] AiToolRegistry isLocalEnv/isProductionEnv 改 URI host 精确解析:防
  http://127.0.0.1.evil.com / localhost.evil.com 伪本地前缀绕过安全门
- [minor] deleteStandard templateId trim + 菜单查询限 isactive=1(两表口径一致,
  不连带删历史同 templateId 菜单/授权)
- [minor] publish roleIds 只接 String 元素(滤 null/非串);warning 改依据
  roleIds.isEmpty()(重复发布不误报)
- [minor] menuauth grantToRoles 改 INSERT...WHERE NOT EXISTS(sys_role_menu 无
  唯一约束,ON CONFLICT 不去重,重复发布会插重复行)+ columnSqlType 空 refTable 抛错

全单测绿(Failures=0)、p0-alter/p1-6 真库验收绿(含幂等+负控)、浏览器 e2e 6/6 绿

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-21 14:15:29 +08:00
parent ccbed82498
commit 46ff5c5779
9 changed files with 136 additions and 61 deletions

View File

@@ -153,17 +153,40 @@ public final class AiToolRegistry {
}
private static boolean isLocalEnv(String targetEnv) {
return targetEnv.isBlank()
|| targetEnv.equals("local")
|| targetEnv.equals("dev")
|| targetEnv.startsWith("localhost")
|| targetEnv.startsWith("127.0.0.1")
|| targetEnv.startsWith("http://localhost")
|| targetEnv.startsWith("http://127.0.0.1");
if (targetEnv.isBlank() || targetEnv.equals("local") || targetEnv.equals("dev")) {
return true;
}
// 解析 host 精确比对,而非 startsWith 前缀:防 http://127.0.0.1.evil.com / http://localhost.evil.com
// 这类「伪本地」域名绕过(对抗审查 major)。与下游 AiLocalReleaseExecutor.safeLocalBase 同口径。
String host = hostOf(targetEnv);
return host.equals("localhost") || host.equals("127.0.0.1")
|| host.equals("::1") || host.equals("0:0:0:0:0:0:0:1");
}
private static boolean isProductionEnv(String targetEnv) {
return targetEnv.equals("prod") || targetEnv.equals("production") || targetEnv.contains("prod");
if (targetEnv.equals("prod") || targetEnv.equals("production")) {
return true;
}
// 只看 host 段含 prod,不再对整 URL/path contains('prod')(避免 http://localhost:8084/prod-test 误判)
return hostOf(targetEnv).contains("prod");
}
/** 从 targetEnv(URL 或裸 host[:port])解析出小写 host(去 IPv6 方括号);解析失败返空串。 */
private static String hostOf(String targetEnv) {
try {
String s = targetEnv.contains("://") ? targetEnv : "http://" + targetEnv;
String host = java.net.URI.create(s).getHost();
if (host == null) {
return "";
}
host = host.toLowerCase(Locale.ROOT);
if (host.startsWith("[") && host.endsWith("]")) {
host = host.substring(1, host.length() - 1);
}
return host;
} catch (RuntimeException e) {
return "";
}
}
private static String text(String value) {