问题描述
我的问题是:在尝试编辑Cookie标头时,我的应用程序阻止了用户登录仪表板时访问仪表板。
为什么会发生:我最近吸收了一个需要包含的更改(setHeader(“ Set-Cookie”,header +“; SameSite = none; Secure”);)系统以符合Chrome及其政策。我正在使用spring saml安全性,但认为与此无关。但是,当我包含标题时,我的API不允许用户将其访问仪表板。
问题实际上出在应用程序的SecutiryController类中的新过滤器中,在以下方法中添加了新过滤器。
@Override
protected void configure(HttpSecurity http) throws Exception {
cors(http)
.authorizeRequests()
.antMatchers("/api/*/pub/**").permitAll()
.antMatchers("/api/*/report/**")
.antMatchers("/api/*/admin/**").hasAuthority(AuthorityType.ROLE_ADMIN.name())
.antMatchers("/api/**").authenticated()
.antMatchers("/v2/api-docs/**").permitAll()
.antMatchers(WEBSOCKET_MATCHER).authenticated()
.antMatchers("/management/health").permitAll()
.antMatchers("/management/**").hasAuthority(AuthorityType.ROLE_ADMIN.name())
.and()
.formLogin()
.loginProcessingUrl(emotionProperties.getSecurity().getForm().getProcessingUrl())
.successHandler(formLoginSuccessHandler())
.failureHandler(new AjaxAuthenticationFailureHandler())
.usernameParameter(emotionProperties.getSecurity().getForm().getUsernameParameter())
.passwordParameter(emotionProperties.getSecurity().getForm().getpasswordParameter())
.and()
.logout()
.invalidateHttpSession(true)
.logoutRequestMatcher(new AntPathRequestMatcher(this.emotionProperties.getSecurity().getlogoutRequestUrl()))
.logoutSuccessHandler(new AjaxlogoutSuccessHandler())
.deleteCookies("JSESSIONID","XXXXX","XXXXXX")
.and()
.sessionManagement()
.maximumSessions(1)
.and()
.sessionFixation()
.newSession()
.and()
.csrf()
.disable()
.headers()
.httpStrictTransportSecurity()
.and()
.cacheControl()
.and()
.xssprotection()
.and()
.frameOptions().disable()
.addHeaderWriter(getWebsocketFrameOptionsHeaderWriter())
.addHeaderWriter(getFrameOptionsHeaderWriter())
.addHeaderWriter(getP3pHeaderWriter())
.and()
.exceptionHandling()
.authenticationEntryPoint(new Http403ForbiddenEntryPoint())
.and()
.addFilterBefore(new TenantContextPersistenceFilter(emotionProperties.getTenants()),SecurityContextPersistenceFilter.class)
.addFilterafter(new SameSiteFilter(),BasicAuthenticationFilter.class);//.addFilterafter(new SameSiteFilter(),BasicAuthenticationFilter.class); -->new filter
}
此过滤器调用以下插入SameSite = none的方法; “安全”标头,以提供跨站点安全操作,如下所示:
public void doFilter (ServletRequest request,ServletResponse response,FilterChain chain) throws IOException,servletexception {
HttpServletResponse resp = (HttpServletResponse) response;
String header = resp.getHeader("Set-Cookie");
if (header!=null && header.contains("JSESSIONID"))
resp.setHeader("Set-Cookie",header + "; SameSite=none; Secure");
chain.doFilter(request,response);
header=header + "; SameSite=none; Secure";
System.out.println("-exiting sitefilter-");
当我评论setHeader行时,该应用程序运行完美。因此问题出在这里,但是没有显示任何日志。 真正的问题是,此新标题已更新,不允许用户登录系统。因此,当我写入用户的凭据并按下登录按钮时,系统会尝试登录到系统(并且我知道它确实可以这样做,因为如果我删除了标头,它就可以正常运行),它最终返回到登录页面,而没有任何错误消息。我不知道自己是否会失明,但无法弄清楚问题出在哪里。
如果我添加另一个具有相同JSessionID且没有Samesite = None参数的标头,会发生什么情况,它是否符合Chrome政策?例如,添加如下所示的Cookie标头: JSESSIONID = A1234567890P;路径= /; HttpOnly
• https://www.yawintutor.com/cant-login-to-my-custom-login-page-spring-boot-security/
• https://stackoverflow.com/questions/44651573/how-to-add-filter-before-my-another-filter-in-spring-security
• https://leaks.wanari.com/2017/11/28/how-to-make-custom-usernamepasswordauthenticationfilter-with-spring-security
• https://stackoverflow.com/questions/45666239/spring-mvc-security-users-still-can-access-login-page-after-successful-login?rq=1
• https://stackoverflow.com/questions/47301060/spring-security-custom-logout-null-pointer-exception?rq=1
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)