Skip to content

Commit

Permalink
Add new settings ForceUseHTTPS
Browse files Browse the repository at this point in the history
  • Loading branch information
support committed Mar 7, 2024
1 parent 5600728 commit cf087e3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/Core/Grand.Infrastructure/Configuration/SecurityConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ public class SecurityConfig
/// </summary>
public bool UseForwardedHeaders { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to force use https
/// </summary>
public bool ForceUseHTTPS { get; set; }

/// <summary>
/// Gets or sets a value for allowedHosts, is used for host filtering to bind your app to specific hostnames
/// </summary>
Expand Down
9 changes: 8 additions & 1 deletion src/Web/Grand.Web.Common/Startup/ForwardedHeadersStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ public void Configure(IApplicationBuilder application, IWebHostEnvironment webHo

var serviceProvider = application.ApplicationServices;
var securityConfig = serviceProvider.GetRequiredService<SecurityConfig>();

if (securityConfig.ForceUseHTTPS)
{
application.Use((context, next) =>
{
context.Request.Scheme = "https";
return next(context);
});
}
if (securityConfig.UseForwardedHeaders)
application.UseGrandForwardedHeaders();

Expand Down
3 changes: 3 additions & 0 deletions src/Web/Grand.Web/App_Data/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
//Use a reverse proxy server - more information you can find at: https://docs.microsoft.com/en-US/aspnet/core/host-and-deploy/linux-nginx
"UseForwardedHeaders": false,

//In some cases, it might not be possible to add forwarded headers to the requests proxied to the app.
"ForceUseHTTPS": false,

//AllowedHosts, is used for host filtering to bind your app to specific hostnames
"AllowedHosts": "*",

Expand Down

0 comments on commit cf087e3

Please sign in to comment.