diff --git a/api/src/main/java/dev/jianmu/api/SpringbootApp.java b/api/src/main/java/dev/jianmu/api/SpringbootApp.java index a08aece4af6df801f0135428db6a61a35c6c4d41..405e917b449ee4b951edbfa45514439bde8e7c6d 100644 --- a/api/src/main/java/dev/jianmu/api/SpringbootApp.java +++ b/api/src/main/java/dev/jianmu/api/SpringbootApp.java @@ -6,9 +6,13 @@ import io.swagger.v3.oas.annotations.enums.SecuritySchemeType; import io.swagger.v3.oas.annotations.info.Info; import io.swagger.v3.oas.annotations.info.License; import io.swagger.v3.oas.annotations.security.SecurityScheme; +import org.apache.tomcat.util.buf.EncodedSolidusHandling; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer; +import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.server.WebServerFactoryCustomizer; import org.springframework.boot.web.servlet.ServletComponentScan; import org.springframework.retry.annotation.EnableRetry; import org.springframework.scheduling.annotation.EnableAsync; @@ -16,12 +20,14 @@ import org.springframework.web.servlet.config.annotation.PathMatchConfigurer; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.util.UrlPathHelper; +import java.util.List; + /** + * @author Ethan Liu * @class SpringbootApp * @description 项目启动类 - * @author Ethan Liu * @create 2021-02-12 15:35 -*/ + */ @SpringBootApplication(scanBasePackages = "dev.jianmu") @MapperScan("dev.jianmu.infrastructure.mapper") @EnableRetry @@ -48,9 +54,8 @@ import org.springframework.web.util.UrlPathHelper; ) ) @ServletComponentScan -public class SpringbootApp implements WebMvcConfigurer { +public class SpringbootApp implements WebMvcConfigurer, WebServerFactoryCustomizer { public static void main(String[] args) { - System.setProperty("org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH", "true"); SpringApplication.run(SpringbootApp.class, args); } @@ -60,4 +65,12 @@ public class SpringbootApp implements WebMvcConfigurer { urlPathHelper.setUrlDecode(false); configurer.setUrlPathHelper(urlPathHelper); } + + // TODO: 此配置有安全隐患,未来产品需要考虑 + @Override + public void customize(TomcatServletWebServerFactory factory) { + TomcatConnectorCustomizer tomcatConnectorCustomizer = + connector -> connector.setEncodedSolidusHandling(EncodedSolidusHandling.DECODE.getValue()); + factory.setTomcatConnectorCustomizers(List.of(tomcatConnectorCustomizer)); + } }