[轻微]WEB服务器启用了OPTIONS方法/如何禁止DELETE,PUT,OPTIONS等协议访问应用程序/tomcat下禁用不安全的http方法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_35624642/article/details/72974606

使用了360网站安全检测 查到有OPTIONS方法


第一步:修改应用程序的web.xml文件的协议

复制代码
<?xml version="1.0" encoding="UTF-8"?>  
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"  
    version="2.4">
复制代码

第二步:在应用程序的web.xml中添加如下的代码即可

复制代码
<security-constraint>  
   <web-resource-collection>  
      <url-pattern>/*</url-pattern>  
      <http-method>PUT</http-method>  
<http-method>DELETE</http-method>  
<http-method>HEAD</http-method>  
<http-method>OPTIONS</http-method>  
<http-method>TRACE</http-method>  
   </web-resource-collection>  
   <auth-constraint>  
   </auth-constraint>  
 </security-constraint>  
 <login-config>  
   <auth-method>BASIC</auth-method>  
 </login-config>
复制代码

 重新部署程序,重启tomcat即可完成

如果用户要验证既可以将POST和GET也添加在其中,重新部署并启动tomcat即可看到效果

以上的代码添加到某一个应用中,也可以添加到tomcat的web.xml中,区别是添加到某一个应用只对某一个应用有效如果添加到tomcat的web.xml中,则对tomcat下所有的应用有效。

< security-constraint >  
    < web-resource-collection >  
       < url-pattern >/*</ url-pattern >  
       < http-method >PUT</ http-method >  
< http-method >DELETE</ http-method >  
< http-method >HEAD</ http-method >  
< http-method >OPTIONS</ http-method >  
< http-method >TRACE</ http-method >  
    </ web-resource-collection >  
    < auth-constraint >  
    </ auth-constraint >  
  </ security-constraint >  
  < login-config >  
    < auth-method >BASIC</ auth-method >  
  </ login-config >

猜你喜欢

转载自blog.csdn.net/qq_35624642/article/details/72974606