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