spring boot使用内嵌的tomcat解决不安全的HTTP方法安全漏洞

最近项目开发完毕,在进行安全测试的时候,爆出了一个中级安全漏洞--不安全的HTTP方法,如果对这个安全漏洞有不明白的地方,可以自行问度娘。

1、传统Web项目的解决方案

在不使用spring boot的情况下,有两种解决方案1、在过滤器中进行拦截,对于不是http安全的方法直接给前端返回错误信息;2、在tomcat的web.xml配置,对不安全的方法进行拦截。下面,我们重点说下第二种方案,因为这种方案对所有可能存在此安全漏洞的系统都启作用,不用在每个系统中都进行处理。在tomcat的web.xml配置文件中,加如如下的配置文件:

<security-constraint>
            <web-resource-collection>
                <url-pattern>/*</url-pattern>
                <http-method>HEAD</http-method>
                <http-method>PUT</http-method>
                <http-method>DELETE</http-method>
                <http-method>OPTIONS</http-method>
                <http-method>TRACE</http-method>
                <http-method>COPY</http-method>
                <http-method>SEARCH</http-method>
                &l
  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Spring Boot 启动内 Tomcat 的过程可以分为以下几个步骤: 1. 配置 Spring Boot 应用程序的 pom.xml 文件,添加以下依赖项: ``` <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> ``` 2. 创建一个 Spring Boot 应用程序类,并在其 main 方法中调用 SpringApplication.run 方法,如下所示: ``` @SpringBootApplication public class MyApp { public static void main(String[] args) { SpringApplication.run(MyApp.class, args); } } ``` 3. 在应用程序配置文件 application.properties 或 application.yml 中配置 Tomcat 服务器相关的属性,例如端口号、上下文路径等,如下所示: ``` # application.properties server.port=8080 server.servlet.context-path=/myapp ``` ``` # application.yml server: port: 8080 servlet: context-path: /myapp ``` 4. 使用 Spring Boot 提供的入式 Tomcat 作为 Web 服务器。Spring Boot 会根据应用程序的配置自动配置 Tomcat 服务器,创建 TomcatEmbeddedServletContainerFactory 对象,并将其注入到 Spring 容器中。 5. 在应用程序启动过程中,Spring Boot 会扫描应用程序中所有的 @Controller、@RestController、@RequestMapping 等注解,并将其注册到 Tomcat 服务器中。 6. 当应用程序收到请求时,Tomcat 服务器会将请求转发给对应的 Controller 方法,Controller 方法会处理请求并返回响应,Tomcat 服务器将响应发送给客户端。 以上就是 Spring Boot 启动内 Tomcat 的过程。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值