x-content-type-options=nosniff

This commit is contained in:
nicolas.dorier 2018-07-12 01:43:16 +09:00
parent 5ee9a92f1e
commit a256dd3277
2 changed files with 30 additions and 0 deletions

View 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;
}
}
}

View File

@ -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 =>