讓tomcat禁止不安全的HTTP方法
<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>
沒有web.xml設定文件,可以透過以下設定進行,簡單來說就是要注入到Spring容器中
@Configuration public class TomcatConfig { @Bean public EmbeddedServletContainerFactory servletContainer() { TomcatEmbeddedServletContainerFactory tomcatServletContainerFactory = new TomcatEmbeddedServletContainerFactory(); tomcatServletContainerFactory.addContextCustomizers(new TomcatContextCustomizer(){ @Override public void customize(Context context) { SecurityConstraint constraint = new SecurityConstraint(); SecurityCollection collection = new SecurityCollection(); //http方法 collection.addMethod("PUT"); collection.addMethod("DELETE"); collection.addMethod("HEAD"); collection.addMethod("OPTIONS"); collection.addMethod("TRACE"); //url匹配表达式 collection.addPattern("/*"); constraint.addCollection(collection); constraint.setAuthConstraint(true); context.addConstraint(constraint ); //设置使用httpOnly context.setUseHttpOnly(true); } }); return tomcatServletContainerFactory; } }
可能會在Web伺服器上上載、修改或刪除Web頁面、腳本和檔案。
"啟用了不安全的HTTP方法:OPTIONS /system HTTP/1.1Allow: HEAD, PUT, DELETE, TRACE, OPTIONS, PATCH
上述方法的用途:
Options、Head、Trace:主要由應用程式來發現和追蹤伺服器支援和網路行為;
解決方案:
<security-constraint> <web-resource-collection> <web-resource-name>disp</web-resource-name> <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> <http-method>PATCH</http-method> </web-resource-collection> <auth-constraint></auth-constraint> </security-constraint>
標籤介紹:
以上是Springboot怎麼使用內建tomcat禁止不安全HTTP的詳細內容。更多資訊請關注PHP中文網其他相關文章!