Skip to content

Commit

Permalink
PT-10550: adds the security headers to all responses (#2680)
Browse files Browse the repository at this point in the history
feat:  adds the security headers to all responses (#2680)
* X-Content-Type-Options: nosniff
* Strict-Transport-Security: max-age=31536000; includeSubDomains - only applied to HTTPS responses
* X-Frame-Options: Deny - only applied to "document" responses
* X-XSS-Protection: 1; mode=block - only applied to "document" responses
* Referrer-Policy: strict-origin-when-cross-origin - only applied to "document" responses
* Content-Security-Policy: object-src 'none'; form-action 'self'; frame-ancestors 'none' - only applied to "document" responses
  • Loading branch information
OlegoO committed Aug 1, 2023
1 parent c5039b0 commit a3327ca
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Primitives;
using VirtoCommerce.Platform.Core.Common;
using VirtoCommerce.Platform.Core.Modularity;
using VirtoCommerce.Platform.Core.Modularity.Exceptions;
using VirtoCommerce.Platform.Core.Settings;
Expand All @@ -19,11 +17,6 @@ namespace VirtoCommerce.Platform.Web.Extensions
{
public static class ApplicationBuilderExtensions
{
private static readonly Dictionary<string, StringValues> CustomHeaders = new()
{
{ "X-Frame-Options", new StringValues("SAMEORIGIN") }
};

public static IApplicationBuilder UsePlatformSettings(this IApplicationBuilder appBuilder)
{
var settingsRegistrar = appBuilder.ApplicationServices.GetRequiredService<ISettingsRegistrar>();
Expand Down Expand Up @@ -61,17 +54,6 @@ public static IApplicationBuilder UseModules(this IApplicationBuilder appBuilder
return appBuilder;
}

public static IApplicationBuilder UseSecurityHeaders(this IApplicationBuilder appBuilder)
{
appBuilder.Use(async (context, next) =>
{
context.Response.Headers.AddRange(CustomHeaders);
await next();
});

return appBuilder;
}

private static IEnumerable<ManifestModuleInfo> GetInstalledModules(IServiceProvider serviceProvider)
{
var moduleCatalog = serviceProvider.GetRequiredService<ILocalModuleCatalog>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down Expand Up @@ -37,6 +37,7 @@
<PackageReference Include="Microsoft.Identity.Client" Version="4.45.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.10.8" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.2.0" />
<PackageReference Include="NetEscapades.AspNetCore.SecurityHeaders" Version="0.20.0" />
<PackageReference Include="OpenIddict.AspNetCore" Version="3.0.4" />
<PackageReference Include="OpenIddict.EntityFrameworkCore" Version="3.0.4" />
<PackageReference Include="Serilog.AspNetCore" Version="6.1.0" />
Expand Down

0 comments on commit a3327ca

Please sign in to comment.