Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions EssentialCSharp.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,20 @@
app.UseSecurityHeadersMiddleware(new SecurityHeadersBuilder()
.AddDefaultSecurePolicy()
.AddContentSecurityPolicy(csp));

// Redirect www.essentialcsharp.com → essentialcsharp.com (permanent 301)
// Must be after UseForwardedHeaders so the Host header reflects the real hostname.
app.Use(async (context, next) =>
{
if (context.Request.Host.Host.StartsWith("www.", StringComparison.OrdinalIgnoreCase))
{
string apexHost = context.Request.Host.Host[4..];
string redirectUrl = $"{context.Request.Scheme}://{apexHost}{context.Request.PathBase}{context.Request.Path}{context.Request.QueryString}";
context.Response.Redirect(redirectUrl, permanent: true);

Check warning

Code scanning / CodeQL

URL redirection from remote source Medium

Untrusted URL redirection due to
user-provided value
.
Untrusted URL redirection due to
user-provided value
.
Untrusted URL redirection due to
user-provided value
.
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
return;
}
await next(context);
});
}
else
{
Expand Down
Loading