Contact: captcha-regio (global/eu) in de token-response en frame-src voor de StrictSite-CSP (CMS-U9 vervolg)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -136,3 +136,71 @@ public class StrictSitePolicyTests
|
||||
return services.BuildServiceProvider();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>NEW tests: the optional frame-src of the StrictSite policy (third-party iframes such as the captcha widget).</summary>
|
||||
public class StrictSiteFrameSourceTests
|
||||
{
|
||||
private const string Global = "https://global.frcapi.com";
|
||||
private const string Eu = "https://eu.frcapi.com";
|
||||
|
||||
[Fact]
|
||||
public void WithoutFrameOrigins_TheHeaderHasNoFrameSrc_AndIsUnchanged()
|
||||
{
|
||||
var plain = CspPolicyCatalog.Build(CspPolicyCatalog.StrictSite, [], [], ["https://a.example"], ["https://a.example"]);
|
||||
var explicitNone = CspPolicyCatalog.Build(CspPolicyCatalog.StrictSite, [], [], ["https://a.example"], ["https://a.example"], []);
|
||||
|
||||
plain.ContentSecurityPolicy.Should().NotContain("frame-src");
|
||||
explicitNone.Should().Be(plain);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WithFrameOrigins_FrameSrcListsSelfAndThemOnly_BeforeObjectSrc()
|
||||
{
|
||||
var set = CspPolicyCatalog.Build(CspPolicyCatalog.StrictSite, [], [], null, null, [Global, Eu + "/"]);
|
||||
|
||||
set.ContentSecurityPolicy.Should().Contain($"frame-src 'self' {Global} {Eu}; object-src 'none'");
|
||||
set.ContentSecurityPolicy.Should().Contain("frame-ancestors 'none'");
|
||||
set.FrameOptions.Should().Be("DENY");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(CspPolicyCatalog.Strict)]
|
||||
[InlineData(CspPolicyCatalog.Relaxed)]
|
||||
public void TheAdminAndRelaxedPolicies_NeverGetTheFrameOrigins(string policy)
|
||||
{
|
||||
var set = CspPolicyCatalog.Build(policy, [], [], null, null, [Global]);
|
||||
|
||||
set.ContentSecurityPolicy.Should().NotContain("frcapi.com");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AFrameOriginWithAPath_IsRejectedAtStartup()
|
||||
{
|
||||
var config = new ConfigurationBuilder().AddInMemoryCollection(new Dictionary<string, string?>
|
||||
{
|
||||
["SecurityHeaders:AllowedSiteFrameOrigins:0"] = "https://global.frcapi.com/some/path",
|
||||
}).Build();
|
||||
var services = new ServiceCollection();
|
||||
services.AddCmsSecurityHeaders(config);
|
||||
using var provider = services.BuildServiceProvider();
|
||||
|
||||
var act = () => provider.GetRequiredService<IOptions<SecurityHeadersOptions>>().Value;
|
||||
|
||||
act.Should().Throw<OptionsValidationException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TheConfiguredFrameOrigins_ReachTheProvider()
|
||||
{
|
||||
var config = new ConfigurationBuilder().AddInMemoryCollection(new Dictionary<string, string?>
|
||||
{
|
||||
["SecurityHeaders:AllowedSiteFrameOrigins:0"] = Global,
|
||||
}).Build();
|
||||
var services = new ServiceCollection();
|
||||
services.AddCmsSecurityHeaders(config);
|
||||
using var provider = services.BuildServiceProvider();
|
||||
|
||||
provider.GetRequiredService<ICspPolicyProvider>().Get(CspPolicyCatalog.StrictSite)
|
||||
.ContentSecurityPolicy.Should().Contain($"frame-src 'self' {Global};");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user