CSRF实施不适用于OAM

问题描述

我们的应用是带角的弹簧靴。出于安全原因,我们需要实施CSRF。我们已经完成了实施,但是仍然禁止403。 确实要使用OAM登录身份验证。尽管在浏览器中将HTTPonly设置为false,我们仍然看到它不是false。我们可以很好地看到令牌。

HttpClientXsrfModule.withOptions({cookieName: 'XSRF-TOKEN',headerName: 'XSRF-TOKEN'})

这是尖角前端中的代码

我们已经在后端实现了以下代码: 配置类:

http
  .httpBasic()
  .and()
  .csrf() // csrf config starts here
  ignoringAntMatchers(CSRF_IGnorE) // URI where CSRF check will not be applied
  .csrftokenRepository(csrftokenRepository()) // defines a repository where tokens are stored
  .and()
  .addFilterafter(new CsrfFilter(),CsrfFilter.class); 

private CsrftokenRepository csrftokenRepository() {
    CookieCsrftokenRepository repo =  CookieCsrftokenRepository.withHttpOnlyFalse();
    /*repo.setHeaderName(CsrfFilter.CSRF_COOKIE_NAME);*/
    repo.setHeaderName("XSRF-TOKEN");
    return repo;
} 

以及过滤器代码

private Filter csrfheaderFilter() {
    return new OncePerRequestFilter() {
        @Override
        protected void doFilterInternal(HttpServletRequest request,HttpServletResponse response,FilterChain filterChain)
                throws servletexception,IOException {
            Csrftoken csrf = (Csrftoken) request.getAttribute(Csrftoken.class
                    .getName());
            if (csrf != null) {
                Cookie cookie = new Cookie("XSRF-TOKEN",csrf.getToken());
                cookie.setPath("/");
                response.addCookie(cookie);
            }
            filterChain.doFilter(request,response);
        }
    };
} ```

Any help and suggestions are welcome.
We are in doubt that may be OAM authentication does not go with CSRF implementation.


解决方法

Angular具有一些内置保护措施,可防止常见的Web应用程序漏洞和攻击,例如XSSCSRF。请参阅以下页面: https://angular.io/guide/security