我们的应用程序是有角度的弹簧引导。出于安全原因,我们需要实施CSRF。我们已经完成了实施,但仍被禁止403项。We确实使用OAM登录身份验证。尽管将HTTPonly设置为false,但在浏览器中,我们发现它不是假的.我们可以很好地看到记号。
HttpClientXsrfModule.withOptions({cookieName: 'XSRF-TOKEN', headerName: 'XSRF-TOKEN'})这是角前部的代码。
我们已经在后端实现了以下代码: Configuration类:
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.发布于 2020-08-19 12:10:37
对于常见的web应用程序漏洞和攻击,如XSS和CSRF,有一些内置的保护措施。请参见以下页面:https://angular.io/guide/security
https://stackoverflow.com/questions/63486523
复制相似问题