SpringBoot整合升级Spring Security 报错 【The request was rejected because the URL was not normalized】
前言
最近LZ给项目框架升级, 从Spring1.x升级到Spring2.x, 在这里就不多赘述两个版本之间的区别以及升级的原因。
关于升级过程中踩的坑,在其他博文中会做比较详细的记录,以便给读者参考,不要掉进同样的坑里。 这里我们讨论一个关于URL中包含双斜杠被拦截的问题。
发现问题
升级框架之后,测试一个功能时,发现报错Http 500, 第一时间怀疑是后台功能报错。打印后台错误日志,发现报错信息:The request was rejected because the URL was not normalized。
之后与升级前相同环境对比发现,相同的功能, 升级之后,URL中包含双斜杠。
分析问题
经过对比不同和错误信息,初步定位问题出在URL上。查询资料得知,Spring Security 在高版本中增加了StrictHttpFirewall类,对URL校验更加严格。于是查看源码:
private static boolean isNormalized(String path) {
if (path == null) {
return true;
} else if (path.indexOf("//") > -1) {
return false;
} else {
int i;
for(int j = path.length(); j > 0; j = i) {
i = path.lastIndexOf(47, j - 1);
int gap = j - i;
if (gap == 2 && path.charAt(i + 1) == '.') {
return false;
}
if (gap == 3 && path.charAt(i + 1) == '.' && path.charAt(i + 2) == '.') {
return false;
}
}
return true;
}
}
解决问题
方法一:修改项目中出现“//”双斜杠的URL路径,哈哈
方法二:自定义FireWall方式允许URL出现双斜杠“//”
参考:Spring 5.0.3 RequestRejectedException: The request was rejected because the URL was not normalized
- 创建允许在URL中使用斜线的自定义防火墙。
@Bean
public HttpFirewall allowUrlEncodedSlashHttpFirewall() {
StrictHttpFirewall firewall = new StrictHttpFirewall();
firewall.setAllowUrlEncodedSlash(true);
return firewall;
}
2.在WebSecurity中配置这个bean。
@Override
public void configure(WebSecurity web) throws Exception {
//@formatter:off
super.configure(web);
web.httpFirewall(allowUrlEncodedSlashHttpFirewall());
....
}
至此,问题解决。
SpringBoot整合升级Spring Security 报错 【The request was rejected because the URL was not normalized】的更多相关文章
- oauth2(spring security)报错method_not_allowed(Request method 'GET' not supported)解决方法
报错信息 <MethodNotAllowed> <error>method_not_allowed</error> <error_description> ...
- spring boot The request was rejected because the URL was not normalized
升级spring boot 1.5.10.RELEASE 版本后,突然发现之前能Nginx代理能请求的地址抛如下异常: org.springframework.security.web.firewal ...
- springboot整合mybatis的时候报错Caused by: java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
今天闲来无事,学习springboot整合mybatis,在bilibili看视频学的,视频中在dao层的interface上面加上org.apache.ibatis.annotations.Mapp ...
- springboot整合websocket后打包报错:javax.websocket.server.ServerContainer not available
项目整合了websocket以后,打包多次都没有成功,原来是报错了,报错内容如下: Error starting ApplicationContext. To display the conditio ...
- SSM 整合 ehcache spring 配置文件报错
添加 <!-- end MyBatis使用ehcache缓存 --> <cache:annotation-driven cache-manager="cacheManage ...
- Spring MVC报错:The request sent by the client was syntactically incorrect ()
原因: 1.参数名称不一致 2.参数类型不一致
- Ajax使用formdata异步上传文件,报错the request was rejected because no multipart boundary was found
基于jQuery的Ajaxs使用FormData上传文件要注意两个参数的设定 processData设为false 把processData设为false,让jquery不要对formData做处理, ...
- 【spring boot】【elasticsearch】spring boot整合elasticsearch,启动报错Caused by: java.lang.IllegalStateException: availableProcessors is already set to [8], rejecting [8
spring boot整合elasticsearch, 启动报错: Caused by: java.lang.IllegalStateException: availableProcessors ], ...
- SpringBoot与jackson.databind兼容报错问题
SpringBoot与jackson.databind兼容报错问题 ———————————————— 1.SpringBoot版本V2.0.0其依赖的jackson-databind版本为V2.9.4 ...
随机推荐
- c# Marshal.PtrToStructure(StructPtr, typeof(T)); 特别注意
以下异常:Marshal.PtrToStructure(StructPtr, typeof(T)); 原因: 在实际使用中 T 没有一个 parameterless constructor 于是加 ...
- [Xcode 实际操作]九、实用进阶-(28)在iTunes Connect(苹果商店的管理后台)中创建一个新的新的APP
目录:[Swift]Xcode实际操作 本文将演示如何在iTunes Connect(苹果商店的管理后台)中创建一个新的新的APP. 首先要做的是打开浏览器,并进入[iTunesConnect网站], ...
- 在接口的实现类里使用@Override注解报错
问题分析 @Override注解用来检测子类对父类或接口的方法的重写是否正确,但有一次我在Eclipse里对接口的实现类里使用@Override注解却报错,不过在父类的子类里使用该注解却是正常的. 百 ...
- 关于 js中的arguments 对象
arguments对象包含了函数运行时的所有参数,arguments[0]就是第一个参数,arguments[1]就是第二个参数,以此类推.这个对象只有在函数体内部,才可以使用. var f = fu ...
- swift SqliteDB使用
操作步骤: 1,在 Build Phases -> Link Binary With Libraries 中点击加号,添加 libsqlite3.0.tbd 到项目中来 2,创建连接头文件B ...
- C# 面向对象之封装
封装是指将类的内部数据隐藏起来不让对象实例直接对其操作,C#中提供了属性机制来对类内部的状态进行操作. 在C#中封装可以通过public.private.protected和internal等关键字来 ...
- python之yagmail发送邮件
yagmail发送邮件 import yagmail yag = yagmail.SMTP(user="xxxxxxxxxx@163.com",password="xxx ...
- python入门之三元运算,存址方式,深浅拷贝
三元运算 格式: name = 值1 if 条件 else 值2 如果条件为True,那么将值1赋值给name,条件为False,那么将值2赋值给name 存址方式 不同的数据类型在内存中的存址方式不 ...
- python学习之队列
import queue task_queue = queue.Queue() #创建队列
- [已读]了不起的Node.js
2015/1/22 昨天下班前看完了这本,也不算看完,redis与mysql部分没有去翻,觉得暂时用不上. 觉得第一部分的内容还不错. 第二部分主要讲fs,tcp和http这三个模块. 第三个部分是例 ...