28 lines
680 B
C#
28 lines
680 B
C#
using Microsoft.AspNetCore.Http;
|
|
|
|
namespace TakeoutSaaS.Shared.Web.Middleware;
|
|
|
|
/// <summary>
|
|
/// 安全响应头中间件
|
|
/// </summary>
|
|
public sealed class SecurityHeadersMiddleware
|
|
{
|
|
private readonly RequestDelegate _next;
|
|
|
|
public SecurityHeadersMiddleware(RequestDelegate next)
|
|
{
|
|
_next = next;
|
|
}
|
|
|
|
public async Task InvokeAsync(HttpContext context)
|
|
{
|
|
var headers = context.Response.Headers;
|
|
headers["X-Content-Type-Options"] = "nosniff";
|
|
headers["X-Frame-Options"] = "DENY";
|
|
headers["X-XSS-Protection"] = "1; mode=block";
|
|
headers["Referrer-Policy"] = "no-referrer";
|
|
await _next(context);
|
|
}
|
|
}
|
|
|