Skip to content

Commit

Permalink
OCC-233: Add StripeContentSecurityPolicyProvider (#425)
Browse files Browse the repository at this point in the history
Co-authored-by: Zoltán Lehóczky <[email protected]>
  • Loading branch information
sarahelsaig and Piedone authored Apr 16, 2024
1 parent 63654f8 commit db85d6a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Lombiq.HelpfulLibraries.AspNetCore.Security;
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

using static Lombiq.HelpfulLibraries.AspNetCore.Security.ContentSecurityPolicyDirectives;

namespace OrchardCore.Commerce.Payment.Stripe.Services;

public class StripeContentSecurityPolicyProvider : IContentSecurityPolicyProvider
{
public ValueTask UpdateAsync(IDictionary<string, string> securityPolicies, HttpContext context)
{
securityPolicies[ScriptSrc] = ContentSecurityPolicyProvider
.GetDirective(securityPolicies, ScriptSrc)
.MergeWordSets("https://js.stripe.com/");

securityPolicies[FrameSrc] = ContentSecurityPolicyProvider
.GetDirective(securityPolicies, FrameSrc)
.MergeWordSets("https://js.stripe.com/");

return ValueTask.CompletedTask;
}
}
2 changes: 2 additions & 0 deletions src/Modules/OrchardCore.Commerce.Payment.Stripe/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@ public override void ConfigureServices(IServiceCollection services)
services.AddScoped<IOrderContentTypeDefinitionExclusionProvider, StripeOrderContentTypeDefinitionExclusionProvider>();

services.Configure<TemplateOptions>(option => option.MemberAccessStrategy.Register<StripePaymentProviderData>());

services.AddContentSecurityPolicyProvider<StripeContentSecurityPolicyProvider>();
}
}

0 comments on commit db85d6a

Please sign in to comment.