diff --git a/src/Nethermind/Nethermind.Config.Test/ConfigProvider_FindIncorrectSettings_Tests.cs b/src/Nethermind/Nethermind.Config.Test/ConfigProvider_FindIncorrectSettings_Tests.cs index ea8fc1d9a4d..63d06109011 100644 --- a/src/Nethermind/Nethermind.Config.Test/ConfigProvider_FindIncorrectSettings_Tests.cs +++ b/src/Nethermind/Nethermind.Config.Test/ConfigProvider_FindIncorrectSettings_Tests.cs @@ -46,7 +46,6 @@ public void NoCategorySettings() { "NETHERMIND_CLI_SWITCH_LOCAL", "http://localhost:80" }, { "NETHERMIND_MONITORING_JOB", "nethermindJob" }, { "NETHERMIND_MONITORING_GROUP", "nethermindGroup" }, - { "NETHERMIND_CORS_ORIGINS", "*" }, { "NETHERMIND_CONFIG", "test2.json" }, { "NETHERMIND_XYZ", "xyz" }, // not existing, should get error { "QWER", "qwerty" } // not Nethermind setting, no error diff --git a/src/Nethermind/Nethermind.Config/INoCategoryConfig.cs b/src/Nethermind/Nethermind.Config/INoCategoryConfig.cs index 2075eb5c5ab..e50dcb39cd1 100644 --- a/src/Nethermind/Nethermind.Config/INoCategoryConfig.cs +++ b/src/Nethermind/Nethermind.Config/INoCategoryConfig.cs @@ -15,9 +15,6 @@ public interface INoCategoryConfig : IConfig [ConfigItem(Description = "Sets the default group name for metrics monitoring.", EnvironmentVariable = "NETHERMIND_MONITORING_GROUP")] public string MonitoringGroup { get; set; } - [ConfigItem(Description = "Defines CORS origins for JSON RPC.", DefaultValue = "*", EnvironmentVariable = "NETHERMIND_CORS_ORIGINS")] - public string CorsOrigins { get; set; } - [ConfigItem(Description = "Defines host value for CLI function \"switchLocal\".", DefaultValue = "http://localhost", EnvironmentVariable = "NETHERMIND_CLI_SWITCH_LOCAL")] public string CliSwitchLocal { get; set; } } diff --git a/src/Nethermind/Nethermind.Config/NoCategoryConfig.cs b/src/Nethermind/Nethermind.Config/NoCategoryConfig.cs index 56d20af3d2b..c3f15bb98a0 100644 --- a/src/Nethermind/Nethermind.Config/NoCategoryConfig.cs +++ b/src/Nethermind/Nethermind.Config/NoCategoryConfig.cs @@ -8,6 +8,5 @@ public class NoCategoryConfig : INoCategoryConfig public string Config { get; set; } = null; public string MonitoringJob { get; set; } public string MonitoringGroup { get; set; } - public string CorsOrigins { get; set; } public string CliSwitchLocal { get; set; } } diff --git a/src/Nethermind/Nethermind.JsonRpc/IJsonRpcConfig.cs b/src/Nethermind/Nethermind.JsonRpc/IJsonRpcConfig.cs index 301b21f850e..a202fcf5986 100644 --- a/src/Nethermind/Nethermind.JsonRpc/IJsonRpcConfig.cs +++ b/src/Nethermind/Nethermind.JsonRpc/IJsonRpcConfig.cs @@ -166,4 +166,7 @@ public interface IJsonRpcConfig : IConfig [ConfigItem(Description = "The error margin used in the `eth_estimateGas` JSON-RPC method, in basis points.", DefaultValue = "150")] int EstimateErrorMargin { get; set; } + + [ConfigItem(Description = "The JSON-RPC server CORS origins.", DefaultValue = "*")] + string[] CorsOrigins { get; set; } } diff --git a/src/Nethermind/Nethermind.JsonRpc/JsonRpcConfig.cs b/src/Nethermind/Nethermind.JsonRpc/JsonRpcConfig.cs index 26d3d32760e..99260c72927 100644 --- a/src/Nethermind/Nethermind.JsonRpc/JsonRpcConfig.cs +++ b/src/Nethermind/Nethermind.JsonRpc/JsonRpcConfig.cs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: LGPL-3.0-only using System; +using System.Collections.Generic; using System.Linq; using Nethermind.Core.Extensions; using Nethermind.JsonRpc.Modules; @@ -57,6 +58,7 @@ public int WebSocketsPort public long? MaxBatchResponseBodySize { get; set; } = 32.MiB(); public long? MaxSimulateBlocksCap { get; set; } = 256; public int EstimateErrorMargin { get; set; } = 150; + public string[] CorsOrigins { get; set; } = ["*"]; }; }; diff --git a/src/Nethermind/Nethermind.Runner/JsonRpc/Startup.cs b/src/Nethermind/Nethermind.Runner/JsonRpc/Startup.cs index 7e970cda02d..c69e0992dc3 100644 --- a/src/Nethermind/Nethermind.Runner/JsonRpc/Startup.cs +++ b/src/Nethermind/Nethermind.Runner/JsonRpc/Startup.cs @@ -22,7 +22,6 @@ using Nethermind.Api; using Nethermind.Config; using Nethermind.Core.Authentication; -using Nethermind.Core.Extensions; using Nethermind.Core.Resettables; using Nethermind.HealthChecks; using Nethermind.JsonRpc; @@ -57,9 +56,10 @@ public void ConfigureServices(IServiceCollection services) }); Bootstrap.Instance.RegisterJsonRpcServices(services); - string corsOrigins = Environment.GetEnvironmentVariable("NETHERMIND_CORS_ORIGINS") ?? "*"; - services.AddCors(c => c.AddPolicy("Cors", - p => p.AllowAnyMethod().AllowAnyHeader().WithOrigins(corsOrigins))); + services.AddCors(options => options.AddDefaultPolicy(builder => builder + .AllowAnyMethod() + .AllowAnyHeader() + .WithOrigins(jsonRpcConfig.CorsOrigins))); services.AddResponseCompression(options => { @@ -79,8 +79,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IJsonRpc app.UseDeveloperExceptionPage(); } - app.UseCors("Cors"); app.UseRouting(); + app.UseCors(); app.UseResponseCompression(); IConfigProvider? configProvider = app.ApplicationServices.GetService();