[輕微]WEB服務器啟用了OPTIONS方法/如何禁止DELETE,PUT,OPTIONS等協議訪問應用程序/tomcat下禁用不安全的http方法


使用了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>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM