如何解决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应用程序漏洞和攻击,例如XSS
和CSRF
。请参阅以下页面:
https://angular.io/guide/security
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。