0

我们的应用程序是一个带角度的弹簧靴。由于安全原因,我们需要实现 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.


4

1 回答 1

0

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

于 2020-08-19T12:10:37.027 回答