Skip to content

Commit 2870870

Browse files
committed
Add X-frame options and Content-Security-Policy
1 parent 8e8ff3f commit 2870870

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

MyApp/Configure.AppHost.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,23 @@ public override void Configure(Container container)
2323

2424
SetConfig(new HostConfig {
2525
IgnorePathInfoPrefixes = { "/appsettings", "/_framework" },
26-
GlobalResponseHeaders = {
27-
{ "X-Frame-Options", "SAMEORIGIN" },
28-
},
26+
});
27+
28+
string[] allowedOrigins = [
29+
"https://localhost:5001",
30+
"https://localhost:5002",
31+
"https://docs.servicestack.net",
32+
"https://servicestack.net",
33+
"https://*.servicestack.net",
34+
];
35+
36+
GlobalResponseFilters.Add((req,res,dto) => {
37+
var origin = req.Headers.Get(HttpHeaders.Origin);
38+
if (origin != null && allowedOrigins.Any(o => origin.StartsWith(o)))
39+
{
40+
res.AddHeader("X-Frame-Options", $"ALLOW-FROM {origin}");
41+
res.AddHeader("Content-Security-Policy", $"frame-ancestors {origin}");
42+
}
2943
});
3044
}
3145
}

0 commit comments

Comments
 (0)