You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
1.5 KiB
25 lines
1.5 KiB
package com.mydreamjob.common.logging;
|
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
|
/** 只对 AI 经历接口收紧日志元数据,其他接口保持现状。 */
|
|
public final class SensitiveEndpointLogPolicy {
|
|
private static final String ROOT="/profile/me/work-experience-optimization";
|
|
private SensitiveEndpointLogPolicy() {}
|
|
public static boolean isWorkExperience(HttpServletRequest request) {
|
|
// servletPath 通常已解码且去掉路径参数;原始 URI 作为前置过滤器和单测的兜底。
|
|
if (matches(request.getServletPath())) return true;
|
|
String path=request.getRequestURI();
|
|
String context=request.getContextPath();
|
|
if(!context.isEmpty() && path.startsWith(context))path=path.substring(context.length());
|
|
// 同时兼容过滤器单测不设置 contextPath 的标准 /api/v1 请求。
|
|
if(path.startsWith("/api/v1/"))path=path.substring("/api/v1".length());
|
|
try { path=org.springframework.web.util.UriUtils.decode(path,java.nio.charset.StandardCharsets.UTF_8); }
|
|
catch(IllegalArgumentException ignored) { /* 非法编码由既有 HTTP/安全链拒绝,不记录异常原文。 */ }
|
|
if(path.startsWith("/api/v1/"))path=path.substring("/api/v1".length());
|
|
path=path.replaceAll(";[^/]*", "");
|
|
return matches(path);
|
|
}
|
|
private static boolean matches(String path) { return path!=null&&(path.equals(ROOT)||path.startsWith(ROOT+"/")); }
|
|
public static String canonicalPath() { return ROOT; }
|
|
}
|
|
|