前言

最近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

https://stackoverflow.com/questions/48453980/spring-5-0-3-requestrejectedexception-the-request-was-rejected-because-the-url/49116274

  1. 创建允许在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】的更多相关文章

  1. oauth2(spring security)报错method_not_allowed(Request method 'GET' not supported)解决方法

    报错信息 <MethodNotAllowed> <error>method_not_allowed</error> <error_description> ...

  2. spring boot The request was rejected because the URL was not normalized

    升级spring boot 1.5.10.RELEASE 版本后,突然发现之前能Nginx代理能请求的地址抛如下异常: org.springframework.security.web.firewal ...

  3. springboot整合mybatis的时候报错Caused by: java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required

    今天闲来无事,学习springboot整合mybatis,在bilibili看视频学的,视频中在dao层的interface上面加上org.apache.ibatis.annotations.Mapp ...

  4. springboot整合websocket后打包报错:javax.websocket.server.ServerContainer not available

    项目整合了websocket以后,打包多次都没有成功,原来是报错了,报错内容如下: Error starting ApplicationContext. To display the conditio ...

  5. SSM 整合 ehcache spring 配置文件报错

    添加 <!-- end MyBatis使用ehcache缓存 --> <cache:annotation-driven cache-manager="cacheManage ...

  6. Spring MVC报错:The request sent by the client was syntactically incorrect ()

    原因: 1.参数名称不一致 2.参数类型不一致

  7. Ajax使用formdata异步上传文件,报错the request was rejected because no multipart boundary was found

    基于jQuery的Ajaxs使用FormData上传文件要注意两个参数的设定 processData设为false 把processData设为false,让jquery不要对formData做处理, ...

  8. 【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 ], ...

  9. SpringBoot与jackson.databind兼容报错问题

    SpringBoot与jackson.databind兼容报错问题 ———————————————— 1.SpringBoot版本V2.0.0其依赖的jackson-databind版本为V2.9.4 ...

随机推荐

  1. c#二维数组传递与拷贝

    定义 string[,] arr = new string[12, 31] 另一种string[][] ary = new string[5][];相当于一维数组 常量二维数组定义, 用readonl ...

  2. 阿里云物联网 .NET Core 客户端 | CZGL.AliIoTClient:3. 订阅Topic与响应Topic

    文档目录: 说明 1. 连接阿里云物联网 2. IoT 客户端 3. 订阅Topic与响应Topic 4. 设备上报属性 4.1 上报位置信息 5. 设置设备属性 6. 设备事件上报 7. 服务调用 ...

  3. iOS7 UITableView Row Height Estimation

    This post is part of a daily series of posts introducing the most exciting new parts of iOS7 for dev ...

  4. Nacos深入浅出(一)

    Nacos代码第一次给我的感觉有点小清新,下面就带大家抽丝剥茧看看源代码,看看阿里大神的东东: 建议大家先把Nacos跑起来,网上有很多教程,最好直接去git里面拉代码,在IDEA里面运行: cons ...

  5. Python-1-基础

    获取用户输入 >>> x = input("x: ") x: 34 >>> y = input("y: ") y: 42 & ...

  6. TensorFlow 模型保存/载入

    我们在上线使用一个算法模型的时候,首先必须将已经训练好的模型保存下来.tensorflow保存模型的方式与sklearn不太一样,sklearn很直接,一个sklearn.externals.jobl ...

  7. Python 去除列表中重复的元素(转载http://blog.csdn.net/zhengnz/article/details/6265282)

    比较容易记忆的是用内置的set l1 = ['b','c','d','b','c','a','a']l2 = list(set(l1))print l2   还有一种据说速度更快的,没测试过两者的速度 ...

  8. 15 使用lambdas和闭包

    1       使用lambdas和闭包 1.1  定义闭包 闭包是一个代码块,代替了方法或类. groovy中的闭包基于后边的构造方式:{list of parameters-> closur ...

  9. 记住,永远不要在MySQL中使用“utf8”-转

    http://www.infoq.com/cn/articles/in-mysql-never-use-utf8-use-utf8 最近我遇到了一个bug,我试着通过Rails在以“utf8”编码的M ...

  10. C#中 添加 删除 查找Xml中子节点

    //添加xml节点    private void AddXml(string image, string title)     {        XmlDocument xmlDoc = new X ...