Skip to content
This repository was archived by the owner on Aug 1, 2021. It is now read-only.

Commit 912f52e

Browse files
committed
Adjusting CSP
1 parent 677bf74 commit 912f52e

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/Frontend/Jp.UI.SSO/Configuration/SecurityHeadersConfiguration.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
using Microsoft.AspNetCore.Builder;
22
using Microsoft.AspNetCore.Hosting;
33
using Microsoft.AspNetCore.HttpOverrides;
4-
using System.Collections.Generic;
54

65
namespace Jp.UI.SSO.Configuration
76
{
87
public static class SecurityHeadersConfiguration
98
{
109
public static void UseSecurityHeaders(this IApplicationBuilder app, IHostingEnvironment env)
1110
{
11+
1212
app.UseForwardedHeaders(new ForwardedHeadersOptions()
1313
{
1414
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
@@ -22,22 +22,28 @@ public static void UseSecurityHeaders(this IApplicationBuilder app, IHostingEnvi
2222
app.UseCsp(options =>
2323
{
2424
options.DefaultSources(o => o.Self());
25+
options.ObjectSources(o => o.None());
26+
options.FrameAncestors(o => o.None());
27+
options.Sandbox(directive => directive.AllowForms().AllowSameOrigin().AllowScripts());
28+
options.BaseUris(configuration => configuration.Self());
2529
options.FrameSources(o => o.Self()
2630
// this custom source can be removed in your build
2731
.CustomSources("https://ghbtns.com"));
28-
options.FrameAncestors(o => o.CustomSources("http:"));
29-
options.StyleSources(o => o.Self());
30-
options.ObjectSources(o => o.None());
32+
33+
if (env.IsProduction())
34+
options.UpgradeInsecureRequests();
3135
options.ImageSources(a =>
3236
{
3337
a.Self();
3438
a.CustomSources = new[] { "data: https:" };
3539
});
3640
options.FontSources(configuration => configuration.Self().CustomSources("https://fonts.googleapis.com/", "https://fonts.gstatic.com/"));
37-
options.ConnectSources(s => s.CustomSources("https://dc.services.visualstudio.com"));
38-
options.ScriptSources(s => s.Self().CustomSources("https://az416426.vo.msecnd.net", @"sha256-ZT3q7lL9GXNGhPTB1Vvrvds2xw/kOV0zoeok2tiV23I="));
41+
options.ConnectSources(s => s.Self().CustomSources("https://dc.services.visualstudio.com"));
42+
options.ScriptSources(s => s.Self().UnsafeInline().CustomSources("https://az416426.vo.msecnd.net"));
3943

4044
});
45+
46+
4147
}
4248

4349
}

src/Frontend/Jp.UI.SSO/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public Startup(IHostingEnvironment environment, ILogger<Startup> logger)
3030
{
3131
builder.AddUserSecrets<Startup>();
3232
}
33-
33+
3434

3535
Configuration = builder.Build();
3636
_environment = environment;

0 commit comments

Comments
 (0)