mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2025-01-19 05:33:31 +01:00
X-XSS-Protection
This commit is contained in:
parent
a256dd3277
commit
5dd57c8064
@ -19,11 +19,11 @@ namespace BTCPayServer.Filters
|
||||
public string Value { get; set; }
|
||||
public void OnActionExecuting(ActionExecutingContext context)
|
||||
{
|
||||
var existing = context.HttpContext.Response.Headers["x-content-type-options"].FirstOrDefault();
|
||||
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");
|
||||
context.HttpContext.Response.Headers.Remove("X-Content-Type-Options");
|
||||
else
|
||||
context.HttpContext.Response.Headers["x-content-type-options"] = Value;
|
||||
context.HttpContext.Response.Headers["X-Content-Type-Options"] = Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,11 +23,11 @@ namespace BTCPayServer.Filters
|
||||
|
||||
public void OnActionExecuting(ActionExecutingContext context)
|
||||
{
|
||||
var existing = context.HttpContext.Response.Headers["x-frame-options"].FirstOrDefault();
|
||||
var existing = context.HttpContext.Response.Headers["X-Frame-Options"].FirstOrDefault();
|
||||
if (existing != null && Value == null)
|
||||
context.HttpContext.Response.Headers.Remove("x-frame-options");
|
||||
context.HttpContext.Response.Headers.Remove("X-Frame-Options");
|
||||
else
|
||||
context.HttpContext.Response.Headers["x-frame-options"] = Value;
|
||||
context.HttpContext.Response.Headers["X-Frame-Options"] = Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
27
BTCPayServer/Filters/XXSSProtectionAttribute.cs
Normal file
27
BTCPayServer/Filters/XXSSProtectionAttribute.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Microsoft.AspNetCore.Mvc.ViewFeatures;
|
||||
using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal;
|
||||
|
||||
namespace BTCPayServer.Filters
|
||||
{
|
||||
public class XXSSProtectionAttribute : Attribute, IActionFilter
|
||||
{
|
||||
public void OnActionExecuted(ActionExecutedContext context)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnActionExecuting(ActionExecutingContext context)
|
||||
{
|
||||
var existing = context.HttpContext.Response.Headers["X-XSS-Protection"].FirstOrDefault();
|
||||
if (existing != null)
|
||||
context.HttpContext.Response.Headers.Remove("X-XSS-Protection");
|
||||
else
|
||||
context.HttpContext.Response.Headers["X-XSS-Protection"] = "1; mode=block";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -80,6 +80,7 @@ namespace BTCPayServer.Hosting
|
||||
{
|
||||
o.Filters.Add(new XFrameOptionsAttribute("DENY"));
|
||||
o.Filters.Add(new XContentTypeOptionsAttribute("nosniff"));
|
||||
o.Filters.Add(new XXSSProtectionAttribute());
|
||||
});
|
||||
|
||||
services.Configure<IdentityOptions>(options =>
|
||||
|
Loading…
Reference in New Issue
Block a user