我可以对来自本机移动应用程序的请求禁用CSRF检查吗?

我正在为我的Web应用程序和移动应用程序编写一个Spring-boot JWT身份验证。对于Web应用程序身份验证,这很简单,服务器使用包含JWT的cookie并使用过滤器来验证令牌。

但是,对于移动应用程序,我需要在每个请求中传递令牌。在我发出POST请求之前,一切正常。我的服务器默认情况下从cookie中获取csrf令牌,并且移动应用程序不需要csrf令牌。如果请求的标头包含类似Bearer xxxxxxx的内容,我可以禁用csrf保护吗?

http.csrf().requireCsrfProtectionmatcher(new RequestMatcher() {

    @Override
    public boolean matches(HttpServletRequest request) {
        // No CSRF due to JWT in header
        String authHeader = tokenHelper.getauthHeaderFromHeader( request );
        if ( authHeader != null && authHeader.startsWith("Bearer ")) {
            return false;
        }
        // CSRF for everything else that is not an API call or an allowedMethod
        return true;
    }
});
twinslovewei 回答:我可以对来自本机移动应用程序的请求禁用CSRF检查吗?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3163882.html

大家都在问