fix(phase-6.1): CR 消项——分页锚点、分片鉴权、中断归属
- 任务中心 keyset 锚点取 offset-1(上一页最后一行),修复第 2 页首行永久丢失
- /api/files/chunk/** 纳入必须凭据的写端点,并按解码路径再判一次堵住百分号编码绕过
- /api/tasks/{id}/interrupted 增加归属闸:普通账号只能打断自己名下任务,
内部令牌/管理角色保持原语义;品牌任务经 BrandTaskHeartbeatSpi.findOwnerUserId 比对
- 新增 TaskInterruptOwnershipTest 3 例,守卫测试扩到 6 例
This commit is contained in:
@@ -141,6 +141,9 @@ public class AdminApiGuardFilter extends OncePerRequestFilter {
|
||||
/** 必须解析得出身份才放行的确切写路径(S0-7/AC-8),不受 {@code user-tool-guard-enabled} 豁免。 */
|
||||
private static final String[] CREDENTIALED_WRITE_PATHS = {"/api/files/upload"};
|
||||
|
||||
/** 分片通道前缀:init/part/status/complete/abort 与整包上传同一归属语义,不许留匿名口。 */
|
||||
private static final String FILES_CHUNK_PATH_PREFIX = "/api/files/chunk";
|
||||
|
||||
/** 打断任务这条动作:只收 {@code /api/tasks/{id}/interrupted},不动同前缀的 pull-pending/heartbeat。 */
|
||||
private static final String TASK_PATH_PREFIX = "/api/tasks/";
|
||||
private static final String TASK_INTERRUPTED_SUFFIX = "/interrupted";
|
||||
@@ -355,15 +358,57 @@ public class AdminApiGuardFilter extends OncePerRequestFilter {
|
||||
*/
|
||||
static boolean isCredentialRequiredWriteEndpoint(String uri) {
|
||||
String path = uri == null ? "" : uri;
|
||||
if (matchesCredentialedWrite(path)) {
|
||||
return true;
|
||||
}
|
||||
// getRequestURI() 保留百分号编码,而容器按解码后的路径路由:
|
||||
// /api/files/%75pload 会落回同一条写动作 ⇒ 再按解码路径判一次,堵住编码绕过。
|
||||
String decoded = decodePath(path);
|
||||
return !decoded.equals(path) && matchesCredentialedWrite(decoded);
|
||||
}
|
||||
|
||||
private static boolean matchesCredentialedWrite(String path) {
|
||||
for (String exact : CREDENTIALED_WRITE_PATHS) {
|
||||
if (path.equals(exact)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// 分片通道(AC-17)是新的写面:匿名 init/part/complete 能占临时盘,
|
||||
// complete 还能把匿名数据转存进公开桶,必须与 /api/files/upload 同口径。
|
||||
if (path.equals(FILES_CHUNK_PATH_PREFIX) || path.startsWith(FILES_CHUNK_PATH_PREFIX + "/")) {
|
||||
return true;
|
||||
}
|
||||
return path.startsWith(TASK_PATH_PREFIX) && path.endsWith(TASK_INTERRUPTED_SUFFIX)
|
||||
&& path.length() > TASK_PATH_PREFIX.length() + TASK_INTERRUPTED_SUFFIX.length();
|
||||
}
|
||||
|
||||
/**
|
||||
* 手写百分号解码:只为匹配 ASCII 写端点,畸形编码原样保留(交给容器 400)。
|
||||
* 不用 {@code UriUtils.decode}——它遇到坏序列抛异常,会在守卫里多长一枚 catch。
|
||||
*/
|
||||
private static String decodePath(String path) {
|
||||
if (path == null || path.indexOf('%') < 0) {
|
||||
return path == null ? "" : path;
|
||||
}
|
||||
StringBuilder out = new StringBuilder(path.length());
|
||||
int i = 0;
|
||||
while (i < path.length()) {
|
||||
char c = path.charAt(i);
|
||||
if (c == '%' && i + 2 < path.length()) {
|
||||
int hi = Character.digit(path.charAt(i + 1), 16);
|
||||
int lo = Character.digit(path.charAt(i + 2), 16);
|
||||
if (hi >= 0 && lo >= 0) {
|
||||
out.append((char) ((hi << 4) + lo));
|
||||
i += 3;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
out.append(c);
|
||||
i++;
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
/** 未强制要求凭据的用户态前缀:只要带了 user_id 参数,归属就得和令牌身份对齐。 */
|
||||
private boolean needsOwnershipBinding(HttpServletRequest request, String uri) {
|
||||
if (!isUserToolPrefix(uri)) {
|
||||
|
||||
Reference in New Issue
Block a user