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

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...