mirror of
https://github.com/aljazceru/btcpayserver.git
synced 2025-12-18 22:44:29 +01:00
* Move TagHelpers to Abstractions Makes them available for use in plugins. Also cleans up the tag helper references in the view code: As we have it in the root view imports, the individual directives in the views are superfluous. * Move CurrenciesSuggestionsTagHelper back To get rid of the Rating dependency in Abstractions.
31 lines
878 B
C#
31 lines
878 B
C#
using System;
|
|
using BTCPayServer.Security;
|
|
using Microsoft.AspNetCore.Razor.TagHelpers;
|
|
|
|
namespace BTCPayServer.Abstractions.TagHelpers;
|
|
|
|
/// <summary>
|
|
/// Add sha256- to allow inline event handlers in a:href=javascript:
|
|
/// </summary>
|
|
[HtmlTargetElement("a", Attributes = "csp-allow")]
|
|
public class CSPA : TagHelper
|
|
{
|
|
private readonly ContentSecurityPolicies _csp;
|
|
public CSPA(ContentSecurityPolicies csp)
|
|
{
|
|
_csp = csp;
|
|
}
|
|
public override void Process(TagHelperContext context, TagHelperOutput output)
|
|
{
|
|
output.Attributes.RemoveAll("csp-allow");
|
|
if (output.Attributes.TryGetAttribute("href", out var attr))
|
|
{
|
|
var v = attr.Value.ToString();
|
|
if (v.StartsWith("javascript:", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
_csp.AllowUnsafeHashes(v);
|
|
}
|
|
}
|
|
}
|
|
}
|