url 在使用 Intellij 时未规范化错误,但在使用 STS 时不是



开发的网站在远程服务器和本地机器上工作正常(使用 STS IDE 时),最近我开始使用 Intellij IDEA(我创建了一个网站代码的副本,没有任何更改),我开始得到 URL 未规范化错误。

Intellij处理Spring安全性的方式是否与STS不同?或者原因可能是什么?

我不想使用自定义的httpfirewal。

@EnableGlobalMethodSecurity(prePostEnabled=true)
@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter{
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(authenticationProvider())
.jdbcAuthentication()
.usersByUsernameQuery(usersQuery)
.authoritiesByUsernameQuery(rolesQuery)
.dataSource(dataSource);
}
@Override
protected void configure(HttpSecurity http) throws Exception {
// URLs matching for access rights
http.authorizeRequests()
.antMatchers( "/", "/contact","/register").permitAll()
.antMatchers("/accounts").hasAnyAuthority("SUPER_USER","ADMIN_USER")
.anyRequest().authenticated()
.and()
// form login
.csrf().disable().formLogin()
.loginPage("/index")
.failureUrl("/index?error=true")
.defaultSuccessUrl("/user")
.usernameParameter("email")
.passwordParameter("password")
.and()
// logout
.logout()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/").and()
.exceptionHandling()
.accessDeniedPage("/access-denied");

}
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/resources/**", "/static/**", "/css/**", "/js/**", "/images/**");
}

这是从属性:

# Spring MVC view prefix.
spring.mvc.view.prefix=/templates/
# Spring MVC view suffix.
spring.mvc.view.suffix=.html

错误是:

org.springframework.security.web.firewall.RequestRejectedException: The request was rejected because the URL was not normalized.

PS:我正在使用JDK8,Spring Boot 2,Spring Security,thymeleaf,Intellij U 2019.2

org.springframework.security.web.firewall.RequestRejectedException: The request was rejected because the URL was not normalized.

使用哪个 IDE 在 springboot 配置的嵌入式服务器上运行相同的源代码时不应有任何差异。当发送到服务器的HTTP请求未规范化时,会发生此错误,该URL包含.//..////.等字符序列 所以我怀疑这是由于您使用不同的URL浏览应用程序。例如,您不小心在 URL 中添加了"/",例如http://127.0.0.1:8080/app//index.html

您可以通过以下方式更改为使用安全性较低的HttpFirewall以避免此类检查:

@Override
public void configure(WebSecurity web) throws Exception {
web.httpFirewall(new DefaultHttpFirewall());
//another configuration .....
}

附言虽然它被称为DefaultHttpFirewall,但它不是 Spring Security 自 4.2.4 以来使用的默认HttpFirewall,它的安全性不如实际的默认StrictHttpFirewall

最新更新