Skip to content

Commit d05fa74

Browse files
shahabganjilinkdotnet
authored andcommitted
Add security headers for enhanced protection
Integrated `NetEscapades.AspNetCore.SecurityHeaders` to enforce default and API-specific security header policies. Updated `Program.cs` to define and use the new security header configurations. Modified project files and dependencies to reference the necessary package for implementation. These updates improve application security against common vulnerabilities.
1 parent e0124e1 commit d05fa74

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/LinkDotNet.Blog.Web/LinkDotNet.Blog.Web.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<PrivateAssets>all</PrivateAssets>
2020
</PackageReference>
2121
<PackageReference Include="Microsoft.Extensions.Options"/>
22+
<PackageReference Include="NetEscapades.AspNetCore.SecurityHeaders"/>
2223
<PackageReference Include="ReverseMarkdown"/>
2324
<PackageReference Include="System.ServiceModel.Syndication"/>
2425
</ItemGroup>

src/LinkDotNet.Blog.Web/Program.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using LinkDotNet.Blog.Web.RegistrationExtensions;
77
using Microsoft.AspNetCore.Builder;
88
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
9+
using Microsoft.Extensions.DependencyInjection;
910
using Microsoft.Extensions.Hosting;
1011

1112
namespace LinkDotNet.Blog.Web;
@@ -25,6 +26,10 @@ public static async Task Main(string[] args)
2526

2627
private static void RegisterServices(WebApplicationBuilder builder)
2728
{
29+
builder.Services.AddSecurityHeaderPolicies()
30+
.SetDefaultPolicy(p => p.AddDefaultSecurityHeaders())
31+
.AddPolicy("API", p => p.AddDefaultApiSecurityHeaders());
32+
2833
builder.Services
2934
.AddHostingServices()
3035
.AddConfiguration()
@@ -49,6 +54,8 @@ private static void RegisterServices(WebApplicationBuilder builder)
4954

5055
private static void ConfigureApp(WebApplication app)
5156
{
57+
app.UseSecurityHeaders();
58+
5259
if (app.Environment.IsDevelopment())
5360
{
5461
app.UseDeveloperExceptionPage();

0 commit comments

Comments
 (0)