-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisableCspAttribute.cs
More file actions
25 lines (22 loc) · 905 Bytes
/
DisableCspAttribute.cs
File metadata and controls
25 lines (22 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
using Galebra.Security.Headers.Csp.Infrastructure;
using Microsoft.AspNetCore.Mvc.Filters;
namespace Galebra.Security.Headers.Csp;
/// <summary>
/// <inheritdoc cref="IDisableCspFilterAttribute"/>.<br/>
/// <see cref="EnforceMode"/> defaults to true
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false)]
public sealed class DisableCspAttribute : ResultFilterAttribute, IDisableCspFilterAttribute
{
/// <summary>
/// <inheritdoc/>.<br/>
/// Defaults to true
/// </summary>
public bool EnforceMode { get; init; } = true;
public override void OnResultExecuting(ResultExecutingContext context)
{
//Set the EnforceMode as an Item object to be retrieved in the middleware
context.HttpContext.Items[CspConstants.DisableCspResultFilterAttributeKey] = EnforceMode;
base.OnResultExecuting(context);
}
}