mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-19 18:11:36 +01:00
x-content-type-options=nosniff
This commit is contained in:
parent
5ee9a92f1e
commit
a256dd3277
29
BTCPayServer/Filters/XContentTypeOptionsAttribute.cs
Normal file
29
BTCPayServer/Filters/XContentTypeOptionsAttribute.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Filters;
|
||||||
|
|
||||||
|
namespace BTCPayServer.Filters
|
||||||
|
{
|
||||||
|
public class XContentTypeOptionsAttribute : Attribute, IActionFilter
|
||||||
|
{
|
||||||
|
public XContentTypeOptionsAttribute(string value)
|
||||||
|
{
|
||||||
|
Value = value;
|
||||||
|
}
|
||||||
|
public void OnActionExecuted(ActionExecutedContext context)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Value { get; set; }
|
||||||
|
public void OnActionExecuting(ActionExecutingContext context)
|
||||||
|
{
|
||||||
|
var existing = context.HttpContext.Response.Headers["x-content-type-options"].FirstOrDefault();
|
||||||
|
if (existing != null && Value == null)
|
||||||
|
context.HttpContext.Response.Headers.Remove("x-content-type-options");
|
||||||
|
else
|
||||||
|
context.HttpContext.Response.Headers["x-content-type-options"] = Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -79,6 +79,7 @@ namespace BTCPayServer.Hosting
|
|||||||
services.AddMvc(o =>
|
services.AddMvc(o =>
|
||||||
{
|
{
|
||||||
o.Filters.Add(new XFrameOptionsAttribute("DENY"));
|
o.Filters.Add(new XFrameOptionsAttribute("DENY"));
|
||||||
|
o.Filters.Add(new XContentTypeOptionsAttribute("nosniff"));
|
||||||
});
|
});
|
||||||
|
|
||||||
services.Configure<IdentityOptions>(options =>
|
services.Configure<IdentityOptions>(options =>
|
||||||
|
Loading…
Reference in New Issue
Block a user