Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/apps
diff options
context:
space:
mode:
authorLeitwolf112026-10-15 18:30:31 +0300
committerLeitwolf112026-10-15 18:30:31 +0300
commitbd83e9e0fba03a4436e4fcfdde33c1e04d1a9c8f (patch)
treed6390125eb9045ab3496f6cee7544f26a183c4ba /apps
parenta7604e755e5bb77729a309daea75b14522d22afe (diff)
downloadprogmaweb-bd83e9e0fba03a4436e4fcfdde33c1e04d1a9c8f.tar.gz
Treat progmasoft.com as an HSTS-preloaded domain
.com has no HSTS requirement of its own, but progmasoft.com is served as if it had one: - Every HTTPS server block of progmasoft.com, www, account and viget sends max-age=63072000; includeSubDomains; preload. The www redirect sent none before. - Plain HTTP only answers the ACME challenge and otherwise redirects to HTTPS, now with a permanent 308 instead of 301. - The API's own HSTS policy, which it adds to HTTPS responses outside development, carries the same values, so a proxied response never shows two different policies. A test checks the header.
Diffstat (limited to 'apps')
-rw-r--r--apps/api-tests/SecurityHeaderTests.cs18
-rw-r--r--apps/api/Program.cs8
2 files changed, 26 insertions, 0 deletions
diff --git a/apps/api-tests/SecurityHeaderTests.cs b/apps/api-tests/SecurityHeaderTests.cs
index 2d53ecf..e355035 100644
--- a/apps/api-tests/SecurityHeaderTests.cs
+++ b/apps/api-tests/SecurityHeaderTests.cs
@@ -4,6 +4,7 @@
using System.Net;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.HttpOverrides;
+using Microsoft.AspNetCore.Mvc.Testing;
using Progmasoft.Progmaweb.Api.Security;
namespace Progmasoft.Progmaweb.Api.Tests;
@@ -41,4 +42,21 @@ public sealed class SecurityHeaderTests
Assert.Contains("frame-ancestors 'none'",
Assert.Single(response.Headers.GetValues("Content-Security-Policy")), StringComparison.Ordinal);
}
+
+ [Fact]
+ public async Task HttpsResponsesCarryThePreloadPolicyNginxSends()
+ {
+ await using AccountApiFactory factory = new();
+ using HttpClient client = factory.CreateClient(new WebApplicationFactoryClientOptions
+ {
+ AllowAutoRedirect = false,
+ BaseAddress = new Uri("https://account.progmasoft.com"),
+ });
+
+ HttpResponseMessage response =
+ await client.GetAsync("/api/v1/status", TestContext.Current.CancellationToken);
+
+ Assert.Equal("max-age=63072000; includeSubDomains; preload",
+ Assert.Single(response.Headers.GetValues("Strict-Transport-Security")));
+ }
}
diff --git a/apps/api/Program.cs b/apps/api/Program.cs
index fd6e97b..3eb96c9 100644
--- a/apps/api/Program.cs
+++ b/apps/api/Program.cs
@@ -47,6 +47,14 @@ if (!string.IsNullOrWhiteSpace(googleClientId) && !string.IsNullOrWhiteSpace(goo
});
}
builder.Services.AddProblemDetails();
+// progmasoft.com is served as if .com required HSTS: the API answers with the same preload header as Nginx, so a
+// proxied response never carries two different policies.
+builder.Services.AddHsts(options =>
+{
+ options.MaxAge = TimeSpan.FromDays(730);
+ options.IncludeSubDomains = true;
+ options.Preload = true;
+});
builder.Services.AddHealthChecks();
builder.Services.AddRateLimiter(options =>
{