From 38ee6fabb40bcedbf73cea33bb0359cb08c1281d Mon Sep 17 00:00:00 2001 From: Pierre Arnaud Date: Sat, 31 Jan 2026 10:01:46 +0100 Subject: [PATCH] Only enable SignalR detailed errors in development Changed EnableDetailedErrors to be conditional based on: - Debugger attached (DebuggerHelper.IsAttached) - context.HostingEnvironment.IsDevelopment() Updated ConfigureServices to accept WebHostBuilderContext to properly access the hosting environment instead of directly reading environment variables. This prevents detailed error messages from being exposed in production builds, which is important for security. --- src/ElectronNET.AspNet/API/WebHostBuilderExtensions.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/ElectronNET.AspNet/API/WebHostBuilderExtensions.cs b/src/ElectronNET.AspNet/API/WebHostBuilderExtensions.cs index 83daafe..1fc8234 100644 --- a/src/ElectronNET.AspNet/API/WebHostBuilderExtensions.cs +++ b/src/ElectronNET.AspNet/API/WebHostBuilderExtensions.cs @@ -10,6 +10,7 @@ using ElectronNET.Runtime.Helpers; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; + using Microsoft.Extensions.Hosting; /// /// Provides extension methods for to enable Electron.NET @@ -90,7 +91,7 @@ builder = builder.UseUrls($"http://{host}:{webPort}"); } - builder = builder.ConfigureServices(services => + builder = builder.ConfigureServices((context, services) => { services.AddTransient(); services.AddSingleton(); @@ -109,8 +110,10 @@ case StartupMethod.UnpackedDotnetFirstSignalR: services.AddSignalR(options => { - // Enable detailed errors for debugging - options.EnableDetailedErrors = true; + // Enable detailed errors only in development for security + options.EnableDetailedErrors = + DebuggerHelper.IsAttached || + context.HostingEnvironment.IsDevelopment(); }); services.AddSingleton(); break;