fix: 第四批修复(结果读取并发化/分页钳制/JWT 密钥强校验/凭据按 id)
性能
- listResultSnapshots 对指针化载荷改并发读取(有界池 + 保序汇总):此前逐行同步对象存储读,
500 行结果文件生成要多花数十秒。仅在确有指针行时才走池——内联 JSON 直接串行读,
避免为本地读取引入调度抖动(性能基准测试容差会被影响)
安全/正确性
- 管理端 GET /{id}/credential 改为按路径 id 查询(此前忽略 id、改用 shop_name,
会出现「路径声明的店铺」与「实际读取凭据的店铺」不一致);凭据 VO 构造抽公共方法
- server profile 下 JWT 密钥缺失即拒绝启动:此前静默回退到公开默认值(等同无防护,
任何人可伪造 token),只留 warn 日志拦不住发布事故;本地/测试 profile 保持宽松
边界
- 分页/条数参数补齐上限钳制(文档早已声明"最大 N"但无校验):
PriceTrack/ShopMatch 的 page_size → 2000;TaskFileJob 的 limit → 1000;
AppearancePatent/Publish 的 limit → 100
This commit is contained in:
@@ -26,6 +26,26 @@ public class JwtService {
|
||||
|
||||
private volatile SecretKey cachedKey;
|
||||
|
||||
@org.springframework.beans.factory.annotation.Value("${spring.profiles.active:}")
|
||||
private String activeProfiles;
|
||||
|
||||
/**
|
||||
* 生产 profile 下密钥缺失即拒绝启动(2026-09 全维度审查)。
|
||||
*
|
||||
* <p>此前未配置时静默回退到内置默认密钥——那是公开值,任何人可据此伪造 token;
|
||||
* 一次 env 丢失就会让全站鉴权形同虚设,只留一行 warn 日志不足以拦住发布。
|
||||
* 本地/测试 profile 保持宽松(否则开发无法启动)。
|
||||
*/
|
||||
@jakarta.annotation.PostConstruct
|
||||
void requireSecretInServerProfile() {
|
||||
boolean serverProfile = activeProfiles != null && activeProfiles.contains("server");
|
||||
if (serverProfile && (props.getJwtSecret() == null || props.getJwtSecret().isBlank())) {
|
||||
throw new IllegalStateException(
|
||||
"server profile 下必须配置 aiimage.auth.jwt-secret(环境变量 AIIMAGE_JWT_SECRET)——"
|
||||
+ "缺失时会回退到公开的默认密钥,token 可被任意伪造");
|
||||
}
|
||||
}
|
||||
|
||||
private SecretKey signingKey() {
|
||||
SecretKey key = cachedKey;
|
||||
if (key == null) {
|
||||
|
||||
Reference in New Issue
Block a user