【问题标题】:CSRF Implementation does not working with OAMCSRF 实施不适用于 OAM
【发布时间】:2020-12-08 16:41:15
【问题描述】:

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

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

这是 Angular 前端的代码。

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

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 spring-security csrf csrf-token x-xsrf-token


    【解决方案1】:

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

    【讨论】:

    • 是的,我们的实现与该页面中提到的完全一样。
    猜你喜欢
    • 2016-09-21
    • 1970-01-01
    • 2021-01-26
    • 2016-03-18
    • 2015-08-11
    • 2011-04-27
    • 2021-08-11
    • 2016-02-05
    • 2014-11-29
    相关资源
    最近更新 更多