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
22 lines
1000 B
C#
22 lines
1000 B
C#
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();
|
||
});
|
||
}
|