如何禁用不安全的请求方式

本文详细介绍了HTTP1.0和1.1版本中支持的请求方法,包括GET、POST、HEAD、PUT、DELETE等,并提供了在web.xml中禁用特定请求方法的配置示例。同时,强调了禁用请求后进行错误页面设置的重要性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

HTTP请求1.0支持:post  get  head

HTTP请求1.1的时候支持了:put delete  options trace connect

可以自行禁止使用哪些请求,只需要在web.xml中添加配置信息:

<security-constraint>      不通过编程就可以限制对某个资源的访问
        <web-resource-collection>
            <url-pattern>/*</url-pattern>                  拦截所有的url
            <http-method>PUT</http-method>        禁止put请求
            <http-method>DELETE</http-method> 禁止delete请求
            <http-method>HEAD</http-method>      禁止head请求
            <http-method>OPTIONS</http-method>禁止options请求
            <http-method>TRACE</http-method>    禁止trace请求
            <http-method>CONNECT</http-method>禁止connect请求
            <http-method>POST</http-method>        禁止post请求(不建议)
            <http-method>GET</http-method>           禁止get请求(不建议)
        </web-resource-collection>
        <auth-constraint></auth-constraint>             授权约束
    </security-constraint>

这样就禁止了所有的请求方式。

如果<url-pattern>报错可以在:<web-app  的xmlns:xsi里添加:                         http://www.springmodules.org/schema/cache/springmodulescache.xsd
               http://www.springmodules.org/schema/cache/springmodulesehcache.xsd

在禁止了一部分请求后,如果再次发送改请求会有相应的错误产生,如:405,403。。。。

建议添加相应的报错页面否则容易暴露自己的tomcat、版本,项目信息,太不安全。

关于post  get  head put delete  options trace connect的相关作用请查阅官方文档

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值