diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c99d0b8670..d409edbb860 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 21.10.9 + +### Bug Fixes +- Fix regression on cors-origin star value +- Fix for ethFeeHistory accepting hex values for blockCount + ## 21.10.8 ### Additions and Improvements diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpService.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpService.java index 5bb4b572ff8..6ee1c8103a5 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpService.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpService.java @@ -792,7 +792,7 @@ private String buildCorsRegexFromConfig() { return ""; } if (config.getCorsAllowedDomains().contains("*")) { - return "*"; + return ".*"; } else { final StringJoiner stringJoiner = new StringJoiner("|"); config.getCorsAllowedDomains().stream().filter(s -> !s.isEmpty()).forEach(stringJoiner::add); diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java index 7ebaf0d87ba..c15df6bd7f8 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistory.java @@ -19,6 +19,7 @@ import org.hyperledger.besu.ethereum.api.jsonrpc.RpcMethod; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.BlockParameter; +import org.hyperledger.besu.ethereum.api.jsonrpc.internal.parameters.UnsignedLongParameter; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcError; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse; import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse; @@ -64,7 +65,11 @@ public String getName() { public JsonRpcResponse response(final JsonRpcRequestContext request) { final Object requestId = request.getRequest().getId(); - final long blockCount = request.getRequiredParameter(0, Long.class); + final long blockCount = + Optional.of(request.getRequiredParameter(0, UnsignedLongParameter.class)) + .map(UnsignedLongParameter::getValue) + .orElse(0L); + if (blockCount < 1 || blockCount > 1024) { return new JsonRpcErrorResponse(requestId, JsonRpcError.INVALID_PARAMS); } diff --git a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/UnsignedLongParameter.java b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/UnsignedLongParameter.java index 74c49855169..603ae288c70 100644 --- a/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/UnsignedLongParameter.java +++ b/ethereum/api/src/main/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/parameters/UnsignedLongParameter.java @@ -28,6 +28,12 @@ public UnsignedLongParameter(final String value) { checkArgument(this.value >= 0); } + @JsonCreator + public UnsignedLongParameter(final long value) { + this.value = value; + checkArgument(this.value >= 0); + } + public long getValue() { return value; } diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceCorsTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceCorsTest.java index 0b8cf755b2a..1b0590f2446 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceCorsTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/JsonRpcHttpServiceCorsTest.java @@ -166,6 +166,21 @@ public void requestWithAnyOriginShouldSucceedWhenCorsIsStart() throws Exception } } + @Test + public void requestFromBrowserExtensionShouldSucceedWhenCorsIsStar() throws Exception { + jsonRpcHttpService = createJsonRpcHttpServiceWithAllowedDomains("*"); + + final Request request = + new Request.Builder() + .url(jsonRpcHttpService.url()) + .header("Origin", "moz-extension://802123e4-a916-2d4e-bebf-384b0e2e86dd") + .build(); + + try (final Response response = client.newCall(request).execute()) { + assertThat(response.isSuccessful()).isTrue(); + } + } + @Test public void requestWithAccessControlRequestMethodShouldReturnAllowedHeaders() throws Exception { jsonRpcHttpService = createJsonRpcHttpServiceWithAllowedDomains("http://foo.io"); diff --git a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistoryTest.java b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistoryTest.java index f8e3ff8d418..fbe68d9b5d6 100644 --- a/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistoryTest.java +++ b/ethereum/api/src/test/java/org/hyperledger/besu/ethereum/api/jsonrpc/internal/methods/EthFeeHistoryTest.java @@ -76,6 +76,8 @@ public void params() { feeHistoryRequest(1, "latest"); // should pass because both required params and optional param given feeHistoryRequest(1, "latest", new double[] {1, 20.4}); + // should pass because both required params and optional param given + feeHistoryRequest("0x1", "latest", new double[] {1, 20.4}); } @Test diff --git a/gradle.properties b/gradle.properties index e497ed71aef..b5a5e64e548 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -version=21.10.9-SNAPSHOT +version=21.10.9 # Workaround for Java 16 and spotless bug 834 https://github.com/diffplug/spotless/issues/834 org.gradle.jvmargs=--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED \