-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding an IContentSecurityPolicyProvider to allow tenant admin login
- Loading branch information
Showing
3 changed files
with
48 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
Lombiq.Hosting.Tenants.Admin.Login/Services/TenantLoginSecurityPolicyProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Lombiq.HelpfulLibraries.AspNetCore.Security; | ||
using Lombiq.Hosting.Tenants.Admin.Login.Filters; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc.Infrastructure; | ||
using OrchardCore.Environment.Shell; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace Lombiq.Hosting.Tenants.Admin.Login.Services; | ||
|
||
internal sealed class TenantLoginSecurityPolicyProvider : IContentSecurityPolicyProvider | ||
{ | ||
private readonly IActionContextAccessor _actionContextAccessor; | ||
private readonly IShellHost _shellHost; | ||
|
||
public TenantLoginSecurityPolicyProvider(IActionContextAccessor actionContextAccessor, IShellHost shellHost) | ||
{ | ||
_actionContextAccessor = actionContextAccessor; | ||
_shellHost = shellHost; | ||
} | ||
|
||
public ValueTask UpdateAsync(IDictionary<string, string> securityPolicies, HttpContext context) | ||
{ | ||
var actionContext = _actionContextAccessor.ActionContext; | ||
|
||
if (!TenantsIndexFilter.IsTenantsEditAction(actionContext)) | ||
{ | ||
return ValueTask.CompletedTask; | ||
} | ||
|
||
var shellName = actionContext.RouteData.Values["Id"].ToString(); | ||
|
||
if (_shellHost.TryGetSettings(shellName, out var shellSettings)) | ||
{ | ||
CspHelper.MergeValues(securityPolicies, ContentSecurityPolicyDirectives.FormAction, shellSettings.RequestUrlHosts); | ||
} | ||
|
||
return ValueTask.CompletedTask; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters