让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:主要由应用程序来发现和跟踪服务器支持和网络行为;
Get:检索文档;
Put和Post:将文档提交到服务器;
Delete:销毁资源或集合;
Mkcol:创建集合
PropFind和PropPatch:针对资源和集合检索和设置属性;
Copy和Move:管理命名空间上下文中的集合和资源;
Lock和Unlock:改写保护
很显然上述操作明细可以对web服务器进行上传、修改、删除等操作,对服务造成威胁。虽然WebDAV有权限控制但是网上一搜还是一大堆的攻击方法,所以如果不需要这些方法还是建议直接屏蔽就好了。
在web应用中的web.xml加上如下内容
<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中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号