首页 > 解决方案 > 使用spring boot 1.5.8、Spring 4.3.21.RELEASE、tomcat 8.5.35时出现目录遍历问题

问题描述

使用 1.5.8 版本的 Spring-boot Web 应用程序时,我面临目录遍历问题,仅在 .war 扩展包中。

项目结构。

app.war-->
      ->css
      ->images
      ->js
      ->META-INF
      ->org-
            ->springframework->boot->loader->jar->Bytes.class
      ->WEB-INF

in which directly able to access. 
http://localhost:3737/app/org/springframework/boot/loader/jar/Bytes.class


If I used 2.x of spring-boot then the issue is not comming.

Spring-boot-->1.5.8.RELEASE
Spring-mvc-->4.3.25.RELEASE
Spring-Security-->security-web-4.2.8.RELEASE
Tomcat-->tomcat-embed-core-8.5.35.jar

同样,我正在尝试使用 Spring Boot 使用 web.xml 安全约束来防止访问。 将 web.xml 安全约束与 Spring Boot 一起使用, 但同样不起作用

标签: javaspring-bootspring-mvcspring-securitytomcat8

解决方案


这种行为在 Spring Boot 2.0 中得到了改进。Spring Boot 1.5已于 2019 年 8 月结束其受支持的生命周期,因此理想情况下,您应该升级到 Spring Boot 2.x。在撰写本文时,2.4.x 和 2.5.x 是受支持的世代。

如果您被困在 Spring Boot 1.5 上,您的选择就会受到限制。您可以使用 jar 打包,也可以构建一个普通的 war 文件(不能使用 运行的文件java -jar)并将其部署到 Tomcat(或另一个 servlet 容器)。您也可以使用Filter404 来响应不需要的请求。


推荐阅读