Spring 5.0.3 抛出错误The request was rejected because the URL was not normalized

2018-03-08 20:10:33
4893次阅读
0个评论

升级Spring 5.0.3和Spring security-5.0.3 后出现错误The request was rejected because the URL was not normalized.

原因是访问路径目录中出现http://127.0.0.1/xxx//xx 这样访问,新版本Spring将默认不允许使用//

解决办法一是将//这种路径删除


解决办法二

使用自定义的StrictHttpFirewall实现来替换默认的spring security 实现

@Bean
public HttpFirewall allowUrlEncodedSlashHttpFirewall() {
    StrictHttpFirewall firewall = new StrictHttpFirewall();
    firewall.setAllowUrlEncodedSlash(true);
    firewall.setAllowSemicolon(true);
    return firewall;
}
然后在WebSecurity中配置这个bean
@Override
public void configure(WebSecurity web) throws Exception {
  super.configure(web);
  // @formatter:off
  web.httpFirewall(allowUrlEncodedSlashHttpFirewall());
...
}

收藏00

登录 后评论。没有帐号? 注册 一个。