问题概述:
我们正在将系统从 CQ5.4 升级到 AEM 6.1。
在现有代码中,我们使用 ajax 引用了 POST.jsp,我们在其中调用身份验证服务来向系统验证外部用户。
当我们对资源 POST.jsp 执行 ajax 发布时,我们收到以下错误。在错误日志中。
com.adobe.granite.csrf.impl.CSRFFilter doFilter:提供的 CSRF token 无效
我们尝试了什么:
但它没有奏效。
其他外部系统POST数据。 (如果我在安全方面错了,请纠正我)
我们还反编译了 com.adobe.granite.csrf.impl.CSRFFilter 并找到了以下代码:
public void doFilter(ServletRequest req, ServletResponse res, FilterChain Chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest)req;
if ((request.getAuthType() != null) && (isFilteredMethod(request)) && (doFilterBasedOnUserAgent(request)) && (!isValidRequest(request))) {
HttpServletResponse response = (HttpServletResponse)res;
this.logger.info("doFilter: the provided CSRF token is invalid");
response.sendError(403);
return;
}
chain.doFilter(req, res);
}
在上面的代码中,
isFilteredMethod 检查当前请求(POST)是否存在于 Adobe Granite CSRF Filter 的配置过滤方法中。
doFilterBasedOnUserAgent 检查当前请求的用户代理是否在配置的用户代理中不存在。
request.getAuthType 在我们的例子中是“FORM”。所以这不会导致(403)。
The isValidRequest gets the request param :cq_csrf_token and checks if this parameter value is valid. (Observed this and is valid in our case and sends the parameter)
那么过滤方法和用户代理的意义是什么?为什么 CSRF 为 POST.jsp 发送 403,尽管所有 CQ 和 AEM 5.x 版本都支持这种 POSTING 请求方式?
最佳答案
所以你可以做几件事——
关于aem - 需要帮助解决和理解 com.adobe.granite.csrf.impl.CSRFFilter doFilter : the provided CSRF token is invalid in AEM 6. 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34063934/