Files
NTBug/web/Helpdesk.Web/Infrastructure/SecurityHeaders.cs
PatTheEvil abd075287c web: založení projektu Helpdesk.Web a layout aplikace
ASP.NET Core MVC (.NET 10) s Bootstrapem 5, layout s menu podle role,
chybové stránky, bezpečnostní hlavičky (CSP, Referrer-Policy) a česká kultura.

Refs #19, #20
2026-12-02 00:20:49 +01:00

22 lines
1000 B
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
namespace Helpdesk.Web.Infrastructure;
/// <summary>Bezpečnostní hlavičky pro všechny odpovědi webu.</summary>
public static class SecurityHeaders
{
// Všechny skripty a styly jsou ze stejného původu (wwwroot), takže CSP nepotřebuje žádné výjimky.
private const string ContentSecurityPolicy =
"default-src 'self'; img-src 'self' data: blob:; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'";
public static IApplicationBuilder UseSecurityHeaders(this IApplicationBuilder app) =>
app.Use(async (context, next) =>
{
var headers = context.Response.Headers;
headers.ContentSecurityPolicy = ContentSecurityPolicy;
headers.XContentTypeOptions = "nosniff";
headers.XFrameOptions = "DENY";
// Odkazy z e-mailů nesou token v URL – nesmí uniknout v hlavičce Referer.
headers["Referrer-Policy"] = "no-referrer";
await next();
});
}