-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
51 lines (43 loc) · 1.87 KB
/
Program.cs
File metadata and controls
51 lines (43 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using SafeWebCore.Abstractions;
using SafeWebCore.Examples.ApiService.Infrastructure;
using SafeWebCore.Extensions;
using SafeWebCore.Options;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
// -----------------------------------------------------------------------
// SafeWebCore: API preset — no CSP (APIs return JSON, not HTML), strict
// transport, CORS, and other headers suited for JSON API services.
// -----------------------------------------------------------------------
builder.Services.AddNetSecureHeadersApiPreset(opts =>
{
// Optional headers: prevent search engines from indexing internal APIs.
opts.EnableXRobotsTag = true;
opts.XRobotsTagValue = "noindex, nofollow";
// Path-based policy: the /internal prefix gets even stricter headers
// and skips CSP entirely since it is only consumed by trusted services.
opts.PathPolicies.Add(new PathPolicyOptions
{
PathPrefix = "/internal",
Options = new NetSecureHeadersOptions
{
EnableHsts = true,
HstsValue = "max-age=63072000; includeSubDomains; preload",
EnableXContentTypeOptions = true,
EnableXRobotsTag = true,
XRobotsTagValue = "noindex, nofollow",
}
});
});
// -----------------------------------------------------------------------
// Register a custom ICspReportSink that appends violations to a JSON-lines
// file next to the binary — useful for offline analysis or forwarding to
// a SIEM. The built-in CspLoggingReportSink (structured log) is still
// active alongside it.
// -----------------------------------------------------------------------
builder.Services.AddSingleton<ICspReportSink, JsonFileCspReportSink>();
var app = builder.Build();
app.UseNetSecureHeaders();
app.UseCspReport();
app.MapControllers();
app.Run();