-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnableCspAttribute.cs
More file actions
39 lines (35 loc) · 1.52 KB
/
EnableCspAttribute.cs
File metadata and controls
39 lines (35 loc) · 1.52 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using Galebra.Security.Headers.Csp.Infrastructure;
using Microsoft.AspNetCore.Mvc.Filters;
namespace Galebra.Security.Headers.Csp;
/// <summary>
/// <inheritdoc cref="IEnableCspFilterAttribute"/><br/>
/// Defaults to the default <see cref="CspPolicyGroup"/>
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false)]
public sealed class EnableCspAttribute : ResultFilterAttribute, IEnableCspFilterAttribute
{
/// <summary>
/// <inheritdoc cref="EnableCspAttribute"/>
/// </summary>
public EnableCspAttribute()
{
}
public string? PolicyGroupName { get; init; }
public override Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
{
return base.OnResultExecutionAsync(context, next);
}
public override void OnResultExecuting(ResultExecutingContext context)
{
/// One could override filter with an if statment, however this is not proper, especially that
/// filter execute differently if they are requested globally or per folder.
//if (context.HttpContext.Items[CspConstants.EnableCspResultFilterAttributeKey] is not null)
//Set the PolicyGroupName as an Item object to be retrieved in the middleware
context.HttpContext.Items[CspConstants.EnableCspResultFilterAttributeKey] = PolicyGroupName;
base.OnResultExecuting(context);
}
public override void OnResultExecuted(ResultExecutedContext context)
{
base.OnResultExecuted(context);
}
}