首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CSRF实现不使用OAM。

CSRF实现不使用OAM。
EN

Stack Overflow用户
提问于 2020-08-19 12:01:01
回答 1查看 72关注 0票数 0

我们的应用程序是有角度的弹簧引导。出于安全原因,我们需要实施CSRF。我们已经完成了实施,但仍被禁止403项。We确实使用OAM登录身份验证。尽管将HTTPonly设置为false,但在浏览器中,我们发现它不是假的.我们可以很好地看到记号。

代码语言:javascript
复制
HttpClientXsrfModule.withOptions({cookieName: 'XSRF-TOKEN', headerName: 'XSRF-TOKEN'})

这是角前部的代码。

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

代码语言:javascript
复制
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;
} 

以及过滤代码:

代码语言:javascript
复制
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.
EN

回答 1

Stack Overflow用户

发布于 2020-08-19 12:10:37

对于常见的web应用程序漏洞和攻击,如XSSCSRF,有一些内置的保护措施。请参见以下页面:https://angular.io/guide/security

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63486523

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档