fix(鉴权): 请求身份全量改走会话出口;公开默认 JWT 密钥从出厂件里摘掉
三件事都属"失败很安静"那一类:
1) 请求自带 user_id 当范围条件。cp-item2 只收了会改状态/花钱的出口,其余 28 支控制器
(进度/列表/详情,本支 18 支、另 10 支因与租户判定收口同文件而随 cp-item3 那笔)照旧把
"这单是谁的"交给调用方自报:A 传 B 的 user_id 就读到 B 的进度,
接口 200、日志无声。现在 190 支取请求身份的 handler 只经一个出口(写类 require/resolve、
读类 resolve),护栏 RequestSuppliedIdentityOutletTest 钉分母 126 写 + 63 读 + 1 豁免
(内部代理通道 InternalUserProxyController Get /user-proxy 按内部令牌放行)。DTO 形态
(控制器把整个 @RequestBody 递给 service)靠"该 DTO 是否声明 userId 字段"的索引识别,
少了这层判据会漏掉一半;进度类 28 支另由 ProgressQueryOwnershipOutletTest 单独钉。
桌面执行器 4.0.44 不带凭据是既定事实,[ownership-anonymous] 按 URI 计数留证据,
哪一支的匿名计数归零才允许把它从 resolve 换成 require。
2) 默认 JWT 密钥。application.yml 原本写的是
`${AIIMAGE_JWT_SECRET:please-change-this-secret-…}`,那个兜底默认值就是 2026-10-07
现网取证到的东西:两台都跑 profile server 且 env 里没有这个键,于是 JwtService 的启动闸门
看到的是公开字面量(非空)——既不拒绝启动也不告警,签出来的 token 任何读过源码的人都能伪造
(含超管)。现在占位符不带默认值、AuthProperties 缺省空串、isInsecure 同时认空串与该字面量,
server profile 缺密钥直接拒绝启动(宁可起不来)。JwtSecretFallbackGuardrailTest 五例钉
"资源文件里不许再出现那个字面量"与"两形都算不安全"。
发版顺序是硬约束:先在 A/B 两台 .env 配好与对方一致的 AIIMAGE_JWT_SECRET,再上新 jar;
轮换会把所有 web 会话退出登录。
3) 菜单写侧的无操作者重载(create/update/delete)删掉——三道闸门对 operator==null 的处置是
return(放行),src/main 里没人调用它们,但这条路在,下一支控制器接上去就是静默的跨公司改删。
读侧 list(String menuType) 是登录态自读与内部代理用的,故意保留,并被点名只许 1 处。
TaskProgressOwnershipSupport / SimilarAsinTaskLightControllerTest / ResultSuccessTimingContractTest
是 handler 加上 HttpServletRequest 之后的既有契约用例订正;SourceScan 补 withoutComments/methodBody
两支取文助手(源码守卫的匹配面必须剥注释,否则 javadoc 里提一句就能把"必须存在"那形喂绿)。
变异自证:RequestSuppliedIdentityOutletTest 4/4(M1 删参数形出口、M2 删 DTO 形出口、
M3 出口只写进注释、M4 isBound 恒真);JwtSecretFallbackGuardrailTest 4/4(J1 恢复 yml 默认值、
J2 恢复 AuthProperties 默认值、J3 闸门退回只判 isBlank、J4 isInsecure 恒真);
MenuWriteOutletOperatorTest 4/4。
This commit is contained in:
+40
-16
@@ -60,13 +60,17 @@ public class WithdrawTaskController {
|
||||
@Operation(summary = "查询取款备选店铺", description = "按当前用户查询已保存的取款备选店铺列表,用于前端勾选后进行匹配和创建取款任务。")
|
||||
public ApiResponse<List<ProductRiskCandidateVo>> listCandidates(
|
||||
@Parameter(name = "user_id", description = "当前登录用户 ID,数据按用户隔离。", required = true, in = ParameterIn.QUERY, example = "1")
|
||||
@RequestParam("user_id") Long userId) {
|
||||
@RequestParam("user_id") Long userId,
|
||||
HttpServletRequest httpRequest) {
|
||||
userId = adminAuthSupport.resolveOwnershipUserId(httpRequest, userId);
|
||||
return ApiResponse.success(withdrawResolveService.listCandidates(userId));
|
||||
}
|
||||
|
||||
@PostMapping("/candidates")
|
||||
@Operation(summary = "新增取款备选店铺", description = "新增一个待处理店铺名到当前用户的取款备选列表;同一用户下店铺名会规范化去重。")
|
||||
public ApiResponse<ProductRiskCandidateVo> addCandidate(@Valid @RequestBody ProductRiskCandidateAddRequest request) {
|
||||
public ApiResponse<ProductRiskCandidateVo> addCandidate(@Valid @RequestBody ProductRiskCandidateAddRequest request,
|
||||
HttpServletRequest httpRequest) {
|
||||
request.setUserId(adminAuthSupport.resolveOwnershipUserId(httpRequest, request.getUserId()));
|
||||
return ApiResponse.success(withdrawResolveService.addCandidate(request));
|
||||
}
|
||||
|
||||
@@ -76,21 +80,27 @@ public class WithdrawTaskController {
|
||||
@Parameter(description = "备选店铺记录主键,即 candidates 接口返回的 id。", required = true, example = "100")
|
||||
@PathVariable Long id,
|
||||
@Parameter(name = "user_id", description = "当前登录用户 ID。", required = true, in = ParameterIn.QUERY, example = "1")
|
||||
@RequestParam("user_id") Long userId) {
|
||||
@RequestParam("user_id") Long userId,
|
||||
HttpServletRequest httpRequest) {
|
||||
userId = adminAuthSupport.resolveOwnershipUserId(httpRequest, userId);
|
||||
withdrawResolveService.deleteCandidate(userId, id);
|
||||
return ApiResponse.success(null);
|
||||
}
|
||||
|
||||
@PostMapping("/candidates/clear")
|
||||
@Operation(summary = "批量清空取款备选店铺", description = "按店铺名批量删除当前用户的备选记录;通常在店铺成功推送到 Python 队列后清理已匹配数据。")
|
||||
public ApiResponse<Void> clearCandidates(@Valid @RequestBody WithdrawCandidateClearRequest request) {
|
||||
public ApiResponse<Void> clearCandidates(@Valid @RequestBody WithdrawCandidateClearRequest request,
|
||||
HttpServletRequest httpRequest) {
|
||||
request.setUserId(adminAuthSupport.resolveOwnershipUserId(httpRequest, request.getUserId()));
|
||||
withdrawResolveService.deleteCandidatesByShopNames(request.getUserId(), request.getShopNames());
|
||||
return ApiResponse.success(null);
|
||||
}
|
||||
|
||||
@PostMapping("/match-shops")
|
||||
@Operation(summary = "匹配取款店铺", description = "根据店铺名称批量查询紫鸟索引,返回店铺 ID、平台、公司名、匹配状态等信息;只有 matched=true 的店铺可创建任务。")
|
||||
public ApiResponse<ProductRiskMatchShopsVo> matchShops(@Valid @RequestBody ProductRiskMatchShopsRequest request) {
|
||||
public ApiResponse<ProductRiskMatchShopsVo> matchShops(@Valid @RequestBody ProductRiskMatchShopsRequest request,
|
||||
HttpServletRequest httpRequest) {
|
||||
request.setUserId(adminAuthSupport.resolveOwnershipUserId(httpRequest, request.getUserId()));
|
||||
return ApiResponse.success(withdrawResolveService.matchShops(request));
|
||||
}
|
||||
|
||||
@@ -98,7 +108,9 @@ public class WithdrawTaskController {
|
||||
@Operation(summary = "查询取款看板统计", description = "返回当前用户的备选店铺数量、已结束任务数、成功任务数、失败任务数。")
|
||||
public ApiResponse<ProductRiskDashboardVo> dashboard(
|
||||
@Parameter(name = "user_id", description = "当前登录用户 ID。", required = true, in = ParameterIn.QUERY, example = "1")
|
||||
@RequestParam("user_id") Long userId) {
|
||||
@RequestParam("user_id") Long userId,
|
||||
HttpServletRequest httpRequest) {
|
||||
userId = adminAuthSupport.resolveOwnershipUserId(httpRequest, userId);
|
||||
return ApiResponse.success(withdrawTaskService.dashboard(userId));
|
||||
}
|
||||
|
||||
@@ -106,31 +118,37 @@ public class WithdrawTaskController {
|
||||
@Operation(summary = "查询取款任务记录", description = "查询当前用户取款模块的运行中和历史结果记录,包含任务状态、下载地址、店铺结果和明细行。")
|
||||
public ApiResponse<WithdrawHistoryVo> history(
|
||||
@Parameter(name = "user_id", description = "当前登录用户 ID。", required = true, in = ParameterIn.QUERY, example = "1")
|
||||
@RequestParam("user_id") Long userId) {
|
||||
@RequestParam("user_id") Long userId,
|
||||
HttpServletRequest httpRequest) {
|
||||
userId = adminAuthSupport.resolveOwnershipUserId(httpRequest, userId);
|
||||
return ApiResponse.success(withdrawTaskService.listHistory(userId));
|
||||
}
|
||||
|
||||
@PostMapping("/tasks/progress/batch")
|
||||
@Operation(summary = "批量查询取款任务进度", description = "前端轮询使用。按任务 ID 批量查询轻量进度和结果快照;不存在的任务 ID 会返回在 missingTaskIds 中。")
|
||||
public ApiResponse<WithdrawTaskBatchVo> taskProgressBatch(@Valid @RequestBody WithdrawTaskBatchRequest request) {
|
||||
// 归属过滤:只查询属于该用户的任务(userId 未传时保持原行为,兼容未升级调用方)
|
||||
public ApiResponse<WithdrawTaskBatchVo> taskProgressBatch(@Valid @RequestBody WithdrawTaskBatchRequest request,
|
||||
HttpServletRequest httpRequest) {
|
||||
return ApiResponse.success(withdrawTaskService.getTaskProgressBatch(progressOwnershipSupport
|
||||
.filterOwnedTaskIds(request.getTaskIds(), request.getUserId())));
|
||||
.filterOwnedTaskIds(request.getTaskIds(),
|
||||
adminAuthSupport.requireOwnershipUserId(httpRequest, request.getUserId()))));
|
||||
}
|
||||
|
||||
@PostMapping("/tasks/progress/light")
|
||||
@Operation(summary = "批量查询任务轻量进度(前端轮询专用)",
|
||||
description = "与 progress/batch 同输入,只返回轻量字段(taskId/status/statusCode/fileStatus/fileError/fileReady/updatedAt/rowsVersion),"
|
||||
+ "不返回行明细内容(仅多一次结果行版本聚合查询),响应体更小;旧 progress/batch 端点保留不动。")
|
||||
public ApiResponse<TaskProgressLightBatchVo> progressLight(@Valid @RequestBody TaskProgressLightRequest request) {
|
||||
// 透传 userId:此前传 null = 不过滤归属,匿名遍历 taskId 即可读他人任务状态(2026-09 审查)
|
||||
return ApiResponse.success(withdrawTaskService.progressLight(request.getTaskIds(), request.getUserId()));
|
||||
public ApiResponse<TaskProgressLightBatchVo> progressLight(@Valid @RequestBody TaskProgressLightRequest request,
|
||||
HttpServletRequest httpRequest) {
|
||||
// user_id 不再由请求体说了算:解析不出会话身份就 401(fail-closed,2026-10-07 收口)
|
||||
return ApiResponse.success(withdrawTaskService.progressLight(request.getTaskIds(),
|
||||
adminAuthSupport.requireOwnershipUserId(httpRequest, request.getUserId())));
|
||||
}
|
||||
|
||||
@PostMapping("/tasks")
|
||||
@Operation(summary = "创建取款任务", description = "为一批已匹配店铺创建一个取款任务,写入任务记录和店铺结果占位记录,并返回 taskId 及初始店铺快照。")
|
||||
public ApiResponse<WithdrawCreateTaskVo> createTask(@Valid @RequestBody WithdrawCreateTaskRequest request,
|
||||
HttpServletRequest httpRequest) {
|
||||
request.setUserId(adminAuthSupport.resolveOwnershipUserId(httpRequest, request.getUserId()));
|
||||
return ApiResponse.success(withdrawTaskService.createTask(request,
|
||||
adminAuthSupport.currentDeviceId(httpRequest)));
|
||||
}
|
||||
@@ -154,7 +172,9 @@ public class WithdrawTaskController {
|
||||
@Parameter(description = "结果记录 ID,即 history/items 中的 resultId。", required = true, example = "1001")
|
||||
@PathVariable Long resultId,
|
||||
@Parameter(name = "user_id", description = "当前登录用户 ID。", required = true, in = ParameterIn.QUERY, example = "1")
|
||||
@RequestParam("user_id") Long userId) {
|
||||
@RequestParam("user_id") Long userId,
|
||||
HttpServletRequest httpRequest) {
|
||||
userId = adminAuthSupport.resolveOwnershipUserId(httpRequest, userId);
|
||||
String url = withdrawTaskService.resolveResultDownloadUrl(resultId, userId);
|
||||
if (url == null || url.isBlank()) {
|
||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "暂无可下载结果");
|
||||
@@ -174,7 +194,9 @@ public class WithdrawTaskController {
|
||||
@Parameter(description = "取款任务 ID。", required = true, example = "200")
|
||||
@PathVariable Long taskId,
|
||||
@Parameter(name = "user_id", description = "当前登录用户 ID。", required = true, in = ParameterIn.QUERY, example = "1")
|
||||
@RequestParam("user_id") Long userId) {
|
||||
@RequestParam("user_id") Long userId,
|
||||
HttpServletRequest httpRequest) {
|
||||
userId = adminAuthSupport.resolveOwnershipUserId(httpRequest, userId);
|
||||
withdrawTaskService.deleteTask(taskId, userId);
|
||||
return ApiResponse.success(null);
|
||||
}
|
||||
@@ -185,7 +207,9 @@ public class WithdrawTaskController {
|
||||
@Parameter(description = "结果记录 ID,即 history/items 中的 resultId。", required = true, example = "1001")
|
||||
@PathVariable Long resultId,
|
||||
@Parameter(name = "user_id", description = "当前登录用户 ID。", required = true, in = ParameterIn.QUERY, example = "1")
|
||||
@RequestParam("user_id") Long userId) {
|
||||
@RequestParam("user_id") Long userId,
|
||||
HttpServletRequest httpRequest) {
|
||||
userId = adminAuthSupport.resolveOwnershipUserId(httpRequest, userId);
|
||||
withdrawTaskService.deleteHistory(resultId, userId);
|
||||
return ApiResponse.success(null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user