mirror of
				https://github.com/dromara/RuoYi-Vue-Plus.git
				synced 2025-11-04 08:13:44 +08:00 
			
		
		
		
	update 优化 拦截爬虫跟踪等垃圾请求
This commit is contained in:
		@@ -1,6 +1,8 @@
 | 
			
		||||
package org.dromara.common.web.config;
 | 
			
		||||
 | 
			
		||||
import io.undertow.server.DefaultByteBufferPool;
 | 
			
		||||
import io.undertow.server.handlers.DisallowedMethodsHandler;
 | 
			
		||||
import io.undertow.util.HttpString;
 | 
			
		||||
import io.undertow.websockets.jsr.WebSocketDeploymentInfo;
 | 
			
		||||
import org.dromara.common.core.utils.SpringUtils;
 | 
			
		||||
import org.springframework.boot.autoconfigure.AutoConfiguration;
 | 
			
		||||
@@ -28,6 +30,15 @@ public class UndertowConfig implements WebServerFactoryCustomizer<UndertowServle
 | 
			
		||||
                deploymentInfo.setExecutor(executor);
 | 
			
		||||
                deploymentInfo.setAsyncExecutor(executor);
 | 
			
		||||
            }
 | 
			
		||||
            deploymentInfo.addInitialHandlerChainWrapper(handler -> {
 | 
			
		||||
                // 禁止三个方法 CONNECT/TRACE/TRACK 也是不安全的 避免爬虫骚扰
 | 
			
		||||
                HttpString[] disallowedHttpMethods = {
 | 
			
		||||
                    HttpString.tryFromString("CONNECT"),
 | 
			
		||||
                    HttpString.tryFromString("TRACE"),
 | 
			
		||||
                    HttpString.tryFromString("TRACK")
 | 
			
		||||
                };
 | 
			
		||||
                return new DisallowedMethodsHandler(handler, disallowedHttpMethods);
 | 
			
		||||
            });
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user