前言

最近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# Marshal.PtrToStructure(StructPtr, typeof(T)); 特别注意

    以下异常:Marshal.PtrToStructure(StructPtr, typeof(T)); 原因:  在实际使用中 T 没有一个 parameterless  constructor 于是加 ...

  2. 51nod1076(tarjan)

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1076 题意:中文题诶- 思路:先用tarjan找出所有桥,再用 ...

  3. Integrative Analysis of MicroRNAome, Transcriptome, and Proteome during the Limb Regeneration of Cynops orientalis (文献分享一组-翁海玉)

    文献名:Integrative Analysis of MicroRNAome, Transcriptome, and Proteome during the Limb Regeneration of ...

  4. SpringBoot 2.0 集成 JavaMail ,实现异步发送邮件

    一.JavaMail的核心API 1.API功能图解 2.API说明 (1).Message 类: javax.mail.Message 类是创建和解析邮件的一个抽象类 子类javax.mail.in ...

  5. springboot2.x 的 RedisCacheManager变化

    springboot2.x 的 RedisCacheManager变化 springboot2.x 的 RedisCacheManager变化 由于最近在学着使用redis做缓存,使用的是spring ...

  6. ShareSDK集成遇到问题

    解决方案

  7. Tinghua Data Mining

    Learning Resources 书籍: 期刊: 业界先驱: 开阔视野,掌握业界最新动态. 工具: 数据挖掘是很多学科的综合体: 甭管叫什么名字,归根到底都是数据挖掘: Comprehensive ...

  8. bzoj 4318 || 洛谷P1654 OSU!

    https://www.lydsy.com/JudgeOnline/problem.php?id=4318 https://www.luogu.org/problemnew/show/P1654 看来 ...

  9. django-Haystack库

    本文参考自Haystack官方文档:https://django-haystack.readthedocs.io/en/master/tutorial.html#configuration 简介 Ha ...

  10. Spring AOP初步总结(二)

    该篇为Spring AOP的一个应用案例:系统日志 需求:将任何删除,更改或新增数据库的操作汇总到数据库中 步骤1:编写切面 @Aspect @Component public class SysLo ...