From 3ebb6aa5c89e8ee9e7052e168d596d4f28eca86c Mon Sep 17 00:00:00 2001 From: spencergibb Date: Mon, 25 Oct 2021 14:29:32 -0400 Subject: [PATCH 1/6] If Transfer-Encoding header is "chunked", then normalize. This means removing the content-length header acccoring to https://datatracker.ietf.org/doc/html/rfc7230#section-3.3.3 Fixes gh-2425 --- .../config/GatewayAutoConfiguration.java | 6 + ...ferEncodingNormalizationHeadersFilter.java | 49 ++++++ ...codingMarmalizationHeadersFilterTests.java | 64 ++++++++ ...alizationHeardsFilterIntegrationTests.java | 152 ++++++++++++++++++ .../transfer-encoding/invalid-request.bin | 13 ++ .../transfer-encoding/valid-request.bin | 7 + 6 files changed, 291 insertions(+) create mode 100644 spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/headers/TransferEncodingNormalizationHeadersFilter.java create mode 100644 spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/headers/TransferEncodingMarmalizationHeadersFilterTests.java create mode 100644 spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/headers/TransferEncodingNormalizationHeardsFilterIntegrationTests.java create mode 100644 spring-cloud-gateway-server/src/test/resources/transfer-encoding/invalid-request.bin create mode 100644 spring-cloud-gateway-server/src/test/resources/transfer-encoding/valid-request.bin diff --git a/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java b/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java index 1feff526..ca9e43f1 100644 --- a/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java +++ b/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/config/GatewayAutoConfiguration.java @@ -107,6 +107,7 @@ import org.springframework.cloud.gateway.filter.factory.rewrite.ModifyResponseBo import org.springframework.cloud.gateway.filter.headers.ForwardedHeadersFilter; import org.springframework.cloud.gateway.filter.headers.HttpHeadersFilter; import org.springframework.cloud.gateway.filter.headers.RemoveHopByHopHeadersFilter; +import org.springframework.cloud.gateway.filter.headers.TransferEncodingNormalizationHeadersFilter; import org.springframework.cloud.gateway.filter.headers.XForwardedHeadersFilter; import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver; import org.springframework.cloud.gateway.filter.ratelimit.PrincipalNameKeyResolver; @@ -286,6 +287,11 @@ public class GatewayAutoConfiguration { return new XForwardedHeadersFilter(); } + @Bean + public TransferEncodingNormalizationHeadersFilter transferEncodingNormalizationHeadersFilter() { + return new TransferEncodingNormalizationHeadersFilter(); + } + // GlobalFilter beans @Bean diff --git a/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/headers/TransferEncodingNormalizationHeadersFilter.java b/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/headers/TransferEncodingNormalizationHeadersFilter.java new file mode 100644 index 00000000..e393c1ec --- /dev/null +++ b/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/headers/TransferEncodingNormalizationHeadersFilter.java @@ -0,0 +1,49 @@ +/* + * Copyright 2013-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.gateway.filter.headers; + +import org.springframework.core.Ordered; +import org.springframework.http.HttpHeaders; +import org.springframework.web.server.ServerWebExchange; + +/** + * See https://datatracker.ietf.org/doc/html/rfc7230#section-3.3.3 for details. + */ +public class TransferEncodingNormalizationHeadersFilter implements HttpHeadersFilter, Ordered { + + @Override + public int getOrder() { + return 1000; + } + + @Override + public HttpHeaders filter(HttpHeaders input, ServerWebExchange exchange) { + String transferEncoding = input.getFirst(HttpHeaders.TRANSFER_ENCODING); + if (transferEncoding != null && "chunked".equalsIgnoreCase(transferEncoding.trim()) + && input.containsKey(HttpHeaders.CONTENT_LENGTH)) { + + HttpHeaders filtered = new HttpHeaders(); + // avoids read only if input is read only + filtered.addAll(input); + filtered.remove(HttpHeaders.CONTENT_LENGTH); + return filtered; + } + + return input; + } + +} diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/headers/TransferEncodingMarmalizationHeadersFilterTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/headers/TransferEncodingMarmalizationHeadersFilterTests.java new file mode 100644 index 00000000..85eaf51a --- /dev/null +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/headers/TransferEncodingMarmalizationHeadersFilterTests.java @@ -0,0 +1,64 @@ +/* + * Copyright 2013-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.gateway.filter.headers; + +import org.junit.Test; + +import org.springframework.http.HttpHeaders; +import org.springframework.mock.http.server.reactive.MockServerHttpRequest; +import org.springframework.mock.web.server.MockServerWebExchange; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * @author Spencer Gibb + */ +public class TransferEncodingMarmalizationHeadersFilterTests { + + @Test + public void noTransferEncodingWithContentLength() { + MockServerHttpRequest.BaseBuilder builder = MockServerHttpRequest.post("http://localhost/post") + .header(HttpHeaders.CONTENT_LENGTH, "6"); + + HttpHeaders headers = testFilter(MockServerWebExchange.from(builder)); + assertThat(headers).containsKey(HttpHeaders.CONTENT_LENGTH).doesNotContainKey(HttpHeaders.TRANSFER_ENCODING); + } + + @Test + public void transferEncodingWithContentLength() { + MockServerHttpRequest.BaseBuilder builder = MockServerHttpRequest.post("http://localhost/post") + .header(HttpHeaders.CONTENT_LENGTH, "6").header(HttpHeaders.TRANSFER_ENCODING, "chunked"); + + HttpHeaders headers = testFilter(MockServerWebExchange.from(builder)); + assertThat(headers).doesNotContainKey(HttpHeaders.CONTENT_LENGTH).containsKey(HttpHeaders.TRANSFER_ENCODING); + } + + @Test + public void transferEncodingCaseInsensitiveWithContentLength() { + MockServerHttpRequest.BaseBuilder builder = MockServerHttpRequest.post("http://localhost/post") + .header(HttpHeaders.CONTENT_LENGTH, "6").header(HttpHeaders.TRANSFER_ENCODING, "Chunked "); + + HttpHeaders headers = testFilter(MockServerWebExchange.from(builder)); + assertThat(headers).doesNotContainKey(HttpHeaders.CONTENT_LENGTH).containsKey(HttpHeaders.TRANSFER_ENCODING); + } + + private HttpHeaders testFilter(MockServerWebExchange exchange) { + TransferEncodingNormalizationHeadersFilter filter = new TransferEncodingNormalizationHeadersFilter(); + return filter.filter(exchange.getRequest().getHeaders(), exchange); + } + +} diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/headers/TransferEncodingNormalizationHeardsFilterIntegrationTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/headers/TransferEncodingNormalizationHeardsFilterIntegrationTests.java new file mode 100644 index 00000000..92c08a18 --- /dev/null +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/headers/TransferEncodingNormalizationHeardsFilterIntegrationTests.java @@ -0,0 +1,152 @@ +/* + * Copyright 2013-2020 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.cloud.gateway.filter.headers; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.Socket; + +import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.jupiter.api.Test; + +import org.springframework.boot.SpringBootConfiguration; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.cloud.client.DefaultServiceInstance; +import org.springframework.cloud.gateway.route.RouteLocator; +import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder; +import org.springframework.cloud.gateway.test.PermitAllSecurityConfiguration; +import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClient; +import org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplier; +import org.springframework.cloud.loadbalancer.support.ServiceInstanceListSuppliers; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Import; +import org.springframework.core.log.LogMessage; +import org.springframework.http.MediaType; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.util.StreamUtils; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; + +@SpringBootTest(properties = {}, webEnvironment = RANDOM_PORT) +@ActiveProfiles("transferencoding") +public class TransferEncodingNormalizationHeardsFilterIntegrationTests { + + private static final Log log = LogFactory.getLog(TransferEncodingNormalizationHeardsFilterIntegrationTests.class); + + @LocalServerPort + private int port; + + @Test + void legitRequestShouldNotFail() throws Exception { + final ClassLoader classLoader = this.getClass().getClassLoader(); + + // Issue a crafted request with smuggling attempt + assert200With("Should Fail", + StreamUtils.copyToByteArray(classLoader.getResourceAsStream("transfer-encoding/invalid-request.bin"))); + + // Issue a legit request, which should not fail + assert200With("Should Not Fail", + StreamUtils.copyToByteArray(classLoader.getResourceAsStream("transfer-encoding/valid-request.bin"))); + } + + private void assert200With(String name, byte[] payload) throws Exception { + final String response = execute("localhost", port, payload); + log.info(LogMessage.format("Request to localhost:%d %s\n%s", port, name, new String(payload))); + assertThat(response).isNotNull(); + log.info(LogMessage.format("Response %s\n%s", name, response)); + assertThat(response).matches("HTTP/1.\\d 200 OK"); + } + + private String execute(String target, int port, byte[] payload) throws IOException { + final Socket socket = new Socket(target, port); + + final OutputStream out = socket.getOutputStream(); + final BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream())); + + out.write(payload); + + final String headResponse = in.readLine(); + + out.close(); + in.close(); + + return headResponse; + } + + @EnableAutoConfiguration + @SpringBootConfiguration + @Import(PermitAllSecurityConfiguration.class) + @LoadBalancerClient(name = "xferenc", configuration = TestLoadBalancerConfig.class) + @RestController + public static class TestConfig { + + @PostMapping(value = "/echo", produces = { MediaType.APPLICATION_JSON_VALUE }) + public Message message(@RequestBody Message message) throws IOException { + return message; + } + + @Bean + public RouteLocator routeLocator(RouteLocatorBuilder builder) { + return builder.routes() + .route("echo", r -> r.path("/route/echo").filters(f -> f.stripPrefix(1)).uri("lb://xferenc")) + .build(); + } + + } + + public static class Message { + + private String message; + + public Message(@JsonProperty("message") String message) { + this.message = message; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + } + + public static class TestLoadBalancerConfig { + + @LocalServerPort + protected int port = 0; + + @Bean + public ServiceInstanceListSupplier staticServiceInstanceListSupplier() { + return ServiceInstanceListSuppliers.from("xferenc", + new DefaultServiceInstance("xferenc" + "-1", "xferenc", "localhost", port, false)); + } + + } + +} diff --git a/spring-cloud-gateway-server/src/test/resources/transfer-encoding/invalid-request.bin b/spring-cloud-gateway-server/src/test/resources/transfer-encoding/invalid-request.bin new file mode 100644 index 00000000..4248e357 --- /dev/null +++ b/spring-cloud-gateway-server/src/test/resources/transfer-encoding/invalid-request.bin @@ -0,0 +1,13 @@ +POST /route/echo HTTP/1.0 +Host: localhost:8080 +Content-Length: 19 +Transfer-encoding: Chunked +Content-Type: application/json +Connection: close + +22 +{"message":"3"} + +GET /nonexistantpath123 HTTP/1.0 +0 + diff --git a/spring-cloud-gateway-server/src/test/resources/transfer-encoding/valid-request.bin b/spring-cloud-gateway-server/src/test/resources/transfer-encoding/valid-request.bin new file mode 100644 index 00000000..d23a2bb3 --- /dev/null +++ b/spring-cloud-gateway-server/src/test/resources/transfer-encoding/valid-request.bin @@ -0,0 +1,7 @@ +POST /route/echo HTTP/1.1 +Host: localhost:8080 +Content-Type: application/json +Content-Length: 15 +Connection: close + +{"message":"3"} \ No newline at end of file From 3e68ef129b8d865e058120262e930f7dd025f237 Mon Sep 17 00:00:00 2001 From: buildmaster Date: Wed, 3 Nov 2021 20:18:47 +0000 Subject: [PATCH 2/6] Update SNAPSHOT to 3.0.5 --- README.adoc | 18 ++---------------- docs/pom.xml | 2 +- docs/src/main/asciidoc/_configprops.adoc | 1 - pom.xml | 2 +- spring-cloud-gateway-dependencies/pom.xml | 4 ++-- .../mvc-failure-analyzer/pom.xml | 2 +- spring-cloud-gateway-integration-tests/pom.xml | 2 +- spring-cloud-gateway-mvc/pom.xml | 2 +- spring-cloud-gateway-sample/pom.xml | 2 +- spring-cloud-gateway-server/pom.xml | 2 +- spring-cloud-gateway-webflux/pom.xml | 2 +- spring-cloud-starter-gateway/pom.xml | 2 +- 12 files changed, 13 insertions(+), 28 deletions(-) diff --git a/README.adoc b/README.adoc index 3e56e049..7a4f9eb7 100644 --- a/README.adoc +++ b/README.adoc @@ -54,23 +54,9 @@ the `.mvn` configuration, so if you find you have to do it to make a build succeed, please raise a ticket to get the settings added to source control. -For hints on how to build the project look in `.travis.yml` if there -is one. There should be a "script" and maybe "install" command. Also -look at the "services" section to see if any services need to be -running locally (e.g. mongo or rabbit). Ignore the git-related bits -that you might find in "before_install" since they're related to setting git -credentials and you already have those. +The projects that require middleware (i.e. Redis) for testing generally +require that a local instance of [Docker](https://www.docker.com/get-started) is installed and running. -The projects that require middleware generally include a -`docker-compose.yml`, so consider using -https://docs.docker.com/compose/[Docker Compose] to run the middeware servers -in Docker containers. See the README in the -https://github.com/spring-cloud-samples/scripts[scripts demo -repository] for specific instructions about the common cases of mongo, -rabbit and redis. - -NOTE: If all else fails, build with the command from `.travis.yml` (usually -`./mvnw install`). === Documentation diff --git a/docs/pom.xml b/docs/pom.xml index 694fafc4..ebe1c91f 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-gateway - 3.0.5-SNAPSHOT + 3.0.5 spring-cloud-gateway-docs jar diff --git a/docs/src/main/asciidoc/_configprops.adoc b/docs/src/main/asciidoc/_configprops.adoc index 7247d901..a94c19a5 100644 --- a/docs/src/main/asciidoc/_configprops.adoc +++ b/docs/src/main/asciidoc/_configprops.adoc @@ -108,7 +108,6 @@ |spring.cloud.gateway.metrics.enabled | `false` | Enables the collection of metrics data. |spring.cloud.gateway.metrics.prefix | `spring.cloud.gateway` | The prefix of all metrics emitted by gateway. |spring.cloud.gateway.metrics.tags | | Tags map that added to metrics. -|spring.cloud.gateway.metrics.tags.path.enabled | `false` | If the collection of metrics data is enabled, enables an extra metric data tag by path. |spring.cloud.gateway.predicate.after.enabled | `true` | Enables the after predicate. |spring.cloud.gateway.predicate.before.enabled | `true` | Enables the before predicate. |spring.cloud.gateway.predicate.between.enabled | `true` | Enables the between predicate. diff --git a/pom.xml b/pom.xml index c0c70828..4846f359 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-gateway - 3.0.5-SNAPSHOT + 3.0.5 pom Spring Cloud Gateway diff --git a/spring-cloud-gateway-dependencies/pom.xml b/spring-cloud-gateway-dependencies/pom.xml index b0de1557..892f39af 100644 --- a/spring-cloud-gateway-dependencies/pom.xml +++ b/spring-cloud-gateway-dependencies/pom.xml @@ -6,12 +6,12 @@ spring-cloud-dependencies-parent org.springframework.cloud - 3.0.5-SNAPSHOT + 3.0.4 spring-cloud-gateway-dependencies - 3.0.5-SNAPSHOT + 3.0.5 pom spring-cloud-gateway-dependencies diff --git a/spring-cloud-gateway-integration-tests/mvc-failure-analyzer/pom.xml b/spring-cloud-gateway-integration-tests/mvc-failure-analyzer/pom.xml index 299ba1be..14dd3a9f 100644 --- a/spring-cloud-gateway-integration-tests/mvc-failure-analyzer/pom.xml +++ b/spring-cloud-gateway-integration-tests/mvc-failure-analyzer/pom.xml @@ -16,7 +16,7 @@ org.springframework.cloud spring-cloud-gateway-integration-tests - 3.0.5-SNAPSHOT + 3.0.5 .. diff --git a/spring-cloud-gateway-integration-tests/pom.xml b/spring-cloud-gateway-integration-tests/pom.xml index 2a8e8729..92c8005d 100644 --- a/spring-cloud-gateway-integration-tests/pom.xml +++ b/spring-cloud-gateway-integration-tests/pom.xml @@ -16,7 +16,7 @@ org.springframework.cloud spring-cloud-gateway - 3.0.5-SNAPSHOT + 3.0.5 .. diff --git a/spring-cloud-gateway-mvc/pom.xml b/spring-cloud-gateway-mvc/pom.xml index 36f353fc..bbf3dcd4 100644 --- a/spring-cloud-gateway-mvc/pom.xml +++ b/spring-cloud-gateway-mvc/pom.xml @@ -11,7 +11,7 @@ org.springframework.cloud spring-cloud-gateway - 3.0.5-SNAPSHOT + 3.0.5 .. diff --git a/spring-cloud-gateway-sample/pom.xml b/spring-cloud-gateway-sample/pom.xml index 459f12a3..e73a9861 100644 --- a/spring-cloud-gateway-sample/pom.xml +++ b/spring-cloud-gateway-sample/pom.xml @@ -16,7 +16,7 @@ org.springframework.cloud spring-cloud-gateway - 3.0.5-SNAPSHOT + 3.0.5 .. diff --git a/spring-cloud-gateway-server/pom.xml b/spring-cloud-gateway-server/pom.xml index bc100403..597213fb 100644 --- a/spring-cloud-gateway-server/pom.xml +++ b/spring-cloud-gateway-server/pom.xml @@ -7,7 +7,7 @@ org.springframework.cloud spring-cloud-gateway - 3.0.5-SNAPSHOT + 3.0.5 .. spring-cloud-gateway-server diff --git a/spring-cloud-gateway-webflux/pom.xml b/spring-cloud-gateway-webflux/pom.xml index 61e6cffb..39d7918b 100644 --- a/spring-cloud-gateway-webflux/pom.xml +++ b/spring-cloud-gateway-webflux/pom.xml @@ -11,7 +11,7 @@ org.springframework.cloud spring-cloud-gateway - 3.0.5-SNAPSHOT + 3.0.5 .. diff --git a/spring-cloud-starter-gateway/pom.xml b/spring-cloud-starter-gateway/pom.xml index ec7ed2e1..7f209689 100644 --- a/spring-cloud-starter-gateway/pom.xml +++ b/spring-cloud-starter-gateway/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-gateway - 3.0.5-SNAPSHOT + 3.0.5 .. spring-cloud-starter-gateway From fb37423ba7f1feacc9871d42f3fb6fac833659bd Mon Sep 17 00:00:00 2001 From: buildmaster Date: Wed, 3 Nov 2021 20:22:22 +0000 Subject: [PATCH 3/6] Going back to snapshots --- README.adoc | 18 ++++++++++++++++-- docs/pom.xml | 2 +- docs/src/main/asciidoc/_configprops.adoc | 1 + pom.xml | 2 +- spring-cloud-gateway-dependencies/pom.xml | 4 ++-- .../mvc-failure-analyzer/pom.xml | 2 +- spring-cloud-gateway-integration-tests/pom.xml | 2 +- spring-cloud-gateway-mvc/pom.xml | 2 +- spring-cloud-gateway-sample/pom.xml | 2 +- spring-cloud-gateway-server/pom.xml | 2 +- spring-cloud-gateway-webflux/pom.xml | 2 +- spring-cloud-starter-gateway/pom.xml | 2 +- 12 files changed, 28 insertions(+), 13 deletions(-) diff --git a/README.adoc b/README.adoc index 7a4f9eb7..3e56e049 100644 --- a/README.adoc +++ b/README.adoc @@ -54,9 +54,23 @@ the `.mvn` configuration, so if you find you have to do it to make a build succeed, please raise a ticket to get the settings added to source control. -The projects that require middleware (i.e. Redis) for testing generally -require that a local instance of [Docker](https://www.docker.com/get-started) is installed and running. +For hints on how to build the project look in `.travis.yml` if there +is one. There should be a "script" and maybe "install" command. Also +look at the "services" section to see if any services need to be +running locally (e.g. mongo or rabbit). Ignore the git-related bits +that you might find in "before_install" since they're related to setting git +credentials and you already have those. +The projects that require middleware generally include a +`docker-compose.yml`, so consider using +https://docs.docker.com/compose/[Docker Compose] to run the middeware servers +in Docker containers. See the README in the +https://github.com/spring-cloud-samples/scripts[scripts demo +repository] for specific instructions about the common cases of mongo, +rabbit and redis. + +NOTE: If all else fails, build with the command from `.travis.yml` (usually +`./mvnw install`). === Documentation diff --git a/docs/pom.xml b/docs/pom.xml index ebe1c91f..694fafc4 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-gateway - 3.0.5 + 3.0.5-SNAPSHOT spring-cloud-gateway-docs jar diff --git a/docs/src/main/asciidoc/_configprops.adoc b/docs/src/main/asciidoc/_configprops.adoc index a94c19a5..7247d901 100644 --- a/docs/src/main/asciidoc/_configprops.adoc +++ b/docs/src/main/asciidoc/_configprops.adoc @@ -108,6 +108,7 @@ |spring.cloud.gateway.metrics.enabled | `false` | Enables the collection of metrics data. |spring.cloud.gateway.metrics.prefix | `spring.cloud.gateway` | The prefix of all metrics emitted by gateway. |spring.cloud.gateway.metrics.tags | | Tags map that added to metrics. +|spring.cloud.gateway.metrics.tags.path.enabled | `false` | If the collection of metrics data is enabled, enables an extra metric data tag by path. |spring.cloud.gateway.predicate.after.enabled | `true` | Enables the after predicate. |spring.cloud.gateway.predicate.before.enabled | `true` | Enables the before predicate. |spring.cloud.gateway.predicate.between.enabled | `true` | Enables the between predicate. diff --git a/pom.xml b/pom.xml index 4846f359..c0c70828 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-gateway - 3.0.5 + 3.0.5-SNAPSHOT pom Spring Cloud Gateway diff --git a/spring-cloud-gateway-dependencies/pom.xml b/spring-cloud-gateway-dependencies/pom.xml index 892f39af..b0de1557 100644 --- a/spring-cloud-gateway-dependencies/pom.xml +++ b/spring-cloud-gateway-dependencies/pom.xml @@ -6,12 +6,12 @@ spring-cloud-dependencies-parent org.springframework.cloud - 3.0.4 + 3.0.5-SNAPSHOT spring-cloud-gateway-dependencies - 3.0.5 + 3.0.5-SNAPSHOT pom spring-cloud-gateway-dependencies diff --git a/spring-cloud-gateway-integration-tests/mvc-failure-analyzer/pom.xml b/spring-cloud-gateway-integration-tests/mvc-failure-analyzer/pom.xml index 14dd3a9f..299ba1be 100644 --- a/spring-cloud-gateway-integration-tests/mvc-failure-analyzer/pom.xml +++ b/spring-cloud-gateway-integration-tests/mvc-failure-analyzer/pom.xml @@ -16,7 +16,7 @@ org.springframework.cloud spring-cloud-gateway-integration-tests - 3.0.5 + 3.0.5-SNAPSHOT .. diff --git a/spring-cloud-gateway-integration-tests/pom.xml b/spring-cloud-gateway-integration-tests/pom.xml index 92c8005d..2a8e8729 100644 --- a/spring-cloud-gateway-integration-tests/pom.xml +++ b/spring-cloud-gateway-integration-tests/pom.xml @@ -16,7 +16,7 @@ org.springframework.cloud spring-cloud-gateway - 3.0.5 + 3.0.5-SNAPSHOT .. diff --git a/spring-cloud-gateway-mvc/pom.xml b/spring-cloud-gateway-mvc/pom.xml index bbf3dcd4..36f353fc 100644 --- a/spring-cloud-gateway-mvc/pom.xml +++ b/spring-cloud-gateway-mvc/pom.xml @@ -11,7 +11,7 @@ org.springframework.cloud spring-cloud-gateway - 3.0.5 + 3.0.5-SNAPSHOT .. diff --git a/spring-cloud-gateway-sample/pom.xml b/spring-cloud-gateway-sample/pom.xml index e73a9861..459f12a3 100644 --- a/spring-cloud-gateway-sample/pom.xml +++ b/spring-cloud-gateway-sample/pom.xml @@ -16,7 +16,7 @@ org.springframework.cloud spring-cloud-gateway - 3.0.5 + 3.0.5-SNAPSHOT .. diff --git a/spring-cloud-gateway-server/pom.xml b/spring-cloud-gateway-server/pom.xml index 597213fb..bc100403 100644 --- a/spring-cloud-gateway-server/pom.xml +++ b/spring-cloud-gateway-server/pom.xml @@ -7,7 +7,7 @@ org.springframework.cloud spring-cloud-gateway - 3.0.5 + 3.0.5-SNAPSHOT .. spring-cloud-gateway-server diff --git a/spring-cloud-gateway-webflux/pom.xml b/spring-cloud-gateway-webflux/pom.xml index 39d7918b..61e6cffb 100644 --- a/spring-cloud-gateway-webflux/pom.xml +++ b/spring-cloud-gateway-webflux/pom.xml @@ -11,7 +11,7 @@ org.springframework.cloud spring-cloud-gateway - 3.0.5 + 3.0.5-SNAPSHOT .. diff --git a/spring-cloud-starter-gateway/pom.xml b/spring-cloud-starter-gateway/pom.xml index 7f209689..ec7ed2e1 100644 --- a/spring-cloud-starter-gateway/pom.xml +++ b/spring-cloud-starter-gateway/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-gateway - 3.0.5 + 3.0.5-SNAPSHOT .. spring-cloud-starter-gateway From e9e0e62779029f42660a728ea59ca76471d4fe46 Mon Sep 17 00:00:00 2001 From: buildmaster Date: Wed, 3 Nov 2021 20:22:22 +0000 Subject: [PATCH 4/6] Bumping versions to 3.0.6-SNAPSHOT after release --- docs/pom.xml | 2 +- pom.xml | 8 ++++---- spring-cloud-gateway-dependencies/pom.xml | 2 +- .../mvc-failure-analyzer/pom.xml | 2 +- spring-cloud-gateway-integration-tests/pom.xml | 2 +- spring-cloud-gateway-mvc/pom.xml | 2 +- spring-cloud-gateway-sample/pom.xml | 2 +- spring-cloud-gateway-server/pom.xml | 2 +- spring-cloud-gateway-webflux/pom.xml | 2 +- spring-cloud-starter-gateway/pom.xml | 2 +- 10 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/pom.xml b/docs/pom.xml index 694fafc4..0f3e947d 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-gateway - 3.0.5-SNAPSHOT + 3.0.6-SNAPSHOT spring-cloud-gateway-docs jar diff --git a/pom.xml b/pom.xml index c0c70828..36f4bb02 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-gateway - 3.0.5-SNAPSHOT + 3.0.6-SNAPSHOT pom Spring Cloud Gateway @@ -15,7 +15,7 @@ org.springframework.cloud spring-cloud-build - 3.0.4 + 3.0.5-SNAPSHOT @@ -54,8 +54,8 @@ 1.0.6.RELEASE 1.8 1.0.0 - 2.0.2 - 3.0.4 + 2.0.3-SNAPSHOT + 3.0.5-SNAPSHOT 1.15.1 diff --git a/spring-cloud-gateway-dependencies/pom.xml b/spring-cloud-gateway-dependencies/pom.xml index b0de1557..7ff8988f 100644 --- a/spring-cloud-gateway-dependencies/pom.xml +++ b/spring-cloud-gateway-dependencies/pom.xml @@ -11,7 +11,7 @@ spring-cloud-gateway-dependencies - 3.0.5-SNAPSHOT + 3.0.6-SNAPSHOT pom spring-cloud-gateway-dependencies diff --git a/spring-cloud-gateway-integration-tests/mvc-failure-analyzer/pom.xml b/spring-cloud-gateway-integration-tests/mvc-failure-analyzer/pom.xml index 299ba1be..96193be6 100644 --- a/spring-cloud-gateway-integration-tests/mvc-failure-analyzer/pom.xml +++ b/spring-cloud-gateway-integration-tests/mvc-failure-analyzer/pom.xml @@ -16,7 +16,7 @@ org.springframework.cloud spring-cloud-gateway-integration-tests - 3.0.5-SNAPSHOT + 3.0.6-SNAPSHOT .. diff --git a/spring-cloud-gateway-integration-tests/pom.xml b/spring-cloud-gateway-integration-tests/pom.xml index 2a8e8729..8e17e211 100644 --- a/spring-cloud-gateway-integration-tests/pom.xml +++ b/spring-cloud-gateway-integration-tests/pom.xml @@ -16,7 +16,7 @@ org.springframework.cloud spring-cloud-gateway - 3.0.5-SNAPSHOT + 3.0.6-SNAPSHOT .. diff --git a/spring-cloud-gateway-mvc/pom.xml b/spring-cloud-gateway-mvc/pom.xml index 36f353fc..faa4d43e 100644 --- a/spring-cloud-gateway-mvc/pom.xml +++ b/spring-cloud-gateway-mvc/pom.xml @@ -11,7 +11,7 @@ org.springframework.cloud spring-cloud-gateway - 3.0.5-SNAPSHOT + 3.0.6-SNAPSHOT .. diff --git a/spring-cloud-gateway-sample/pom.xml b/spring-cloud-gateway-sample/pom.xml index 459f12a3..c6d7f81d 100644 --- a/spring-cloud-gateway-sample/pom.xml +++ b/spring-cloud-gateway-sample/pom.xml @@ -16,7 +16,7 @@ org.springframework.cloud spring-cloud-gateway - 3.0.5-SNAPSHOT + 3.0.6-SNAPSHOT .. diff --git a/spring-cloud-gateway-server/pom.xml b/spring-cloud-gateway-server/pom.xml index bc100403..117b1d8e 100644 --- a/spring-cloud-gateway-server/pom.xml +++ b/spring-cloud-gateway-server/pom.xml @@ -7,7 +7,7 @@ org.springframework.cloud spring-cloud-gateway - 3.0.5-SNAPSHOT + 3.0.6-SNAPSHOT .. spring-cloud-gateway-server diff --git a/spring-cloud-gateway-webflux/pom.xml b/spring-cloud-gateway-webflux/pom.xml index 61e6cffb..152673a7 100644 --- a/spring-cloud-gateway-webflux/pom.xml +++ b/spring-cloud-gateway-webflux/pom.xml @@ -11,7 +11,7 @@ org.springframework.cloud spring-cloud-gateway - 3.0.5-SNAPSHOT + 3.0.6-SNAPSHOT .. diff --git a/spring-cloud-starter-gateway/pom.xml b/spring-cloud-starter-gateway/pom.xml index ec7ed2e1..3660b70f 100644 --- a/spring-cloud-starter-gateway/pom.xml +++ b/spring-cloud-starter-gateway/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-gateway - 3.0.5-SNAPSHOT + 3.0.6-SNAPSHOT .. spring-cloud-starter-gateway From 1f987594778dbdca5cd27f8a15ef1f94030f6d7c Mon Sep 17 00:00:00 2001 From: spencergibb Date: Thu, 4 Nov 2021 15:34:29 -0400 Subject: [PATCH 5/6] fixes test names --- ...erEncodingNormalizationHeadersFilterIntegrationTests.java} | 4 ++-- ...a => TransferEncodingNormalizationHeadersFilterTests.java} | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/headers/{TransferEncodingNormalizationHeardsFilterIntegrationTests.java => TransferEncodingNormalizationHeadersFilterIntegrationTests.java} (97%) rename spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/headers/{TransferEncodingMarmalizationHeadersFilterTests.java => TransferEncodingNormalizationHeadersFilterTests.java} (97%) diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/headers/TransferEncodingNormalizationHeardsFilterIntegrationTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/headers/TransferEncodingNormalizationHeadersFilterIntegrationTests.java similarity index 97% rename from spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/headers/TransferEncodingNormalizationHeardsFilterIntegrationTests.java rename to spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/headers/TransferEncodingNormalizationHeadersFilterIntegrationTests.java index 92c08a18..66e74240 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/headers/TransferEncodingNormalizationHeardsFilterIntegrationTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/headers/TransferEncodingNormalizationHeadersFilterIntegrationTests.java @@ -53,9 +53,9 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen @SpringBootTest(properties = {}, webEnvironment = RANDOM_PORT) @ActiveProfiles("transferencoding") -public class TransferEncodingNormalizationHeardsFilterIntegrationTests { +public class TransferEncodingNormalizationHeadersFilterIntegrationTests { - private static final Log log = LogFactory.getLog(TransferEncodingNormalizationHeardsFilterIntegrationTests.class); + private static final Log log = LogFactory.getLog(TransferEncodingNormalizationHeadersFilterIntegrationTests.class); @LocalServerPort private int port; diff --git a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/headers/TransferEncodingMarmalizationHeadersFilterTests.java b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/headers/TransferEncodingNormalizationHeadersFilterTests.java similarity index 97% rename from spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/headers/TransferEncodingMarmalizationHeadersFilterTests.java rename to spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/headers/TransferEncodingNormalizationHeadersFilterTests.java index 85eaf51a..07d7bbbb 100644 --- a/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/headers/TransferEncodingMarmalizationHeadersFilterTests.java +++ b/spring-cloud-gateway-server/src/test/java/org/springframework/cloud/gateway/filter/headers/TransferEncodingNormalizationHeadersFilterTests.java @@ -27,7 +27,7 @@ import static org.assertj.core.api.Assertions.assertThat; /** * @author Spencer Gibb */ -public class TransferEncodingMarmalizationHeadersFilterTests { +public class TransferEncodingNormalizationHeadersFilterTests { @Test public void noTransferEncodingWithContentLength() { From ad22f981256108605c9ad7615b14620b35dde310 Mon Sep 17 00:00:00 2001 From: WEIZIBIN Date: Thu, 21 Oct 2021 21:40:16 +0800 Subject: [PATCH 6/6] Use redis time rather than client time. That way consisten time is used across a cluster of gateways. Fixes gh-2411 Fixes gh-2412 --- .../cloud/gateway/filter/ratelimit/RedisRateLimiter.java | 4 +--- .../resources/META-INF/scripts/request_rate_limiter.lua | 6 ++++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/ratelimit/RedisRateLimiter.java b/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/ratelimit/RedisRateLimiter.java index dfa4a00e..1e93a8d4 100644 --- a/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/ratelimit/RedisRateLimiter.java +++ b/spring-cloud-gateway-server/src/main/java/org/springframework/cloud/gateway/filter/ratelimit/RedisRateLimiter.java @@ -16,7 +16,6 @@ package org.springframework.cloud.gateway.filter.ratelimit; -import java.time.Instant; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -250,8 +249,7 @@ public class RedisRateLimiter extends AbstractRateLimiter keys = getKeys(id); // The arguments to the LUA script. time() returns unixtime in seconds. - List scriptArgs = Arrays.asList(replenishRate + "", burstCapacity + "", - Instant.now().getEpochSecond() + "", requestedTokens + ""); + List scriptArgs = Arrays.asList(replenishRate + "", burstCapacity + "", "", requestedTokens + ""); // allowed, tokens_left = redis.eval(SCRIPT, keys, args) Flux> flux = this.redisTemplate.execute(this.script, keys, scriptArgs); // .log("redisratelimiter", Level.FINER); diff --git a/spring-cloud-gateway-server/src/main/resources/META-INF/scripts/request_rate_limiter.lua b/spring-cloud-gateway-server/src/main/resources/META-INF/scripts/request_rate_limiter.lua index de316dd2..36a01733 100644 --- a/spring-cloud-gateway-server/src/main/resources/META-INF/scripts/request_rate_limiter.lua +++ b/spring-cloud-gateway-server/src/main/resources/META-INF/scripts/request_rate_limiter.lua @@ -1,10 +1,12 @@ +redis.replicate_commands() + local tokens_key = KEYS[1] local timestamp_key = KEYS[2] --redis.log(redis.LOG_WARNING, "tokens_key " .. tokens_key) local rate = tonumber(ARGV[1]) local capacity = tonumber(ARGV[2]) -local now = tonumber(ARGV[3]) +local now = redis.call('TIME')[1] local requested = tonumber(ARGV[4]) local fill_time = capacity/rate @@ -12,7 +14,7 @@ local ttl = math.floor(fill_time*2) --redis.log(redis.LOG_WARNING, "rate " .. ARGV[1]) --redis.log(redis.LOG_WARNING, "capacity " .. ARGV[2]) ---redis.log(redis.LOG_WARNING, "now " .. ARGV[3]) +--redis.log(redis.LOG_WARNING, "now " .. now) --redis.log(redis.LOG_WARNING, "requested " .. ARGV[4]) --redis.log(redis.LOG_WARNING, "filltime " .. fill_time) --redis.log(redis.LOG_WARNING, "ttl " .. ttl)