Skip to content

Commit 40a49de

Browse files
committed
Consolidate origins + remove AntiForgery
1 parent 0a3dc3a commit 40a49de

File tree

3 files changed

+11
-18
lines changed

3 files changed

+11
-18
lines changed

MyApp/Configure.AppHost.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,9 @@ public override void Configure(Container container)
2525
IgnorePathInfoPrefixes = { "/appsettings", "/_framework" },
2626
});
2727

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-
3628
PreRequestFilters.Add((req,res) => {
3729
var origin = req.Headers.Get(HttpHeaders.Origin);
38-
if (origin != null && allowedOrigins.Any(o => origin.StartsWith(o)))
30+
if (origin != null && ConfigureCors.Origins.Any(o => origin.StartsWith(o)))
3931
{
4032
res.AddHeader("X-Frame-Options", $"ALLOW-FROM {origin}");
4133
res.AddHeader("Content-Security-Policy", $"frame-ancestors {origin}");

MyApp/Configure.Cors.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@ namespace MyApp;
44

55
public class ConfigureCors : IHostingStartup
66
{
7+
public static string[] Origins = [
8+
"http://localhost:5000", "https://localhost:5001", "https://localhost:5002", "http://localhost:8080",
9+
"https://localhost:5173", "http://localhost:5173",
10+
"https://docs.servicestack.net","https://servicestack.net","https://account.servicestack.net",
11+
"https://razor-ssg.web-templates.io", "https://razor-press.web-templates.io",
12+
"https://press-vue.servicestack.net", "https://press-react.servicestack.net",
13+
"https://vue-spa.web-templates.io", "https://react-spa.web-templates.io",
14+
];
715
public void Configure(IWebHostBuilder builder) => builder
816
.ConfigureServices(services =>
917
{
1018
services.AddCors(options => {
1119
options.AddDefaultPolicy(policy => {
12-
policy.WithOrigins([
13-
"http://localhost:5000", "https://localhost:5001", "https://localhost:5002", "http://localhost:8080",
14-
"https://localhost:5173", "http://localhost:5173",
15-
"https://docs.servicestack.net","https://servicestack.net","https://account.servicestack.net",
16-
"https://razor-ssg.web-templates.io", "https://razor-press.web-templates.io",
17-
"https://press-vue.servicestack.net", "https://press-react.servicestack.net",
18-
"https://vue-spa.web-templates.io", "https://react-spa.web-templates.io",
19-
])
20+
policy.WithOrigins(Origins)
2021
.AllowCredentials()
2122
.WithHeaders(["Content-Type", "Allow", "Authorization"])
2223
.SetPreflightMaxAge(TimeSpan.FromHours(1));

MyApp/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
app.UseHttpsRedirection();
9393

9494
app.UseStaticFiles();
95-
app.UseAntiforgery();
95+
//app.UseAntiforgery(); remove X-Frame-Options header
9696

9797
app.MapRazorComponents<App>()
9898
.AddInteractiveServerRenderMode()

0 commit comments

Comments
 (0)