Security: frame-src van het StrictSite-beleid zonder 'self' #33
@@ -154,11 +154,11 @@ public class StrictSiteFrameSourceTests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void WithFrameOrigins_FrameSrcListsSelfAndThemOnly_BeforeObjectSrc()
|
public void WithFrameOrigins_FrameSrcListsThemOnly_WithoutSelf_BeforeObjectSrc()
|
||||||
{
|
{
|
||||||
var set = CspPolicyCatalog.Build(CspPolicyCatalog.StrictSite, [], [], null, null, [Global, Eu + "/"]);
|
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-src {Global} {Eu}; object-src 'none'");
|
||||||
set.ContentSecurityPolicy.Should().Contain("frame-ancestors 'none'");
|
set.ContentSecurityPolicy.Should().Contain("frame-ancestors 'none'");
|
||||||
set.FrameOptions.Should().Be("DENY");
|
set.FrameOptions.Should().Be("DENY");
|
||||||
}
|
}
|
||||||
@@ -201,6 +201,6 @@ public class StrictSiteFrameSourceTests
|
|||||||
using var provider = services.BuildServiceProvider();
|
using var provider = services.BuildServiceProvider();
|
||||||
|
|
||||||
provider.GetRequiredService<ICspPolicyProvider>().Get(CspPolicyCatalog.StrictSite)
|
provider.GetRequiredService<ICspPolicyProvider>().Get(CspPolicyCatalog.StrictSite)
|
||||||
.ContentSecurityPolicy.Should().Contain($"frame-src 'self' {Global};");
|
.ContentSecurityPolicy.Should().Contain($"frame-src {Global};");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,8 @@ public static class CspPolicyCatalog
|
|||||||
.Where(origin => !string.IsNullOrWhiteSpace(origin)).ToArray();
|
.Where(origin => !string.IsNullOrWhiteSpace(origin)).ToArray();
|
||||||
if (frames.Length > 0)
|
if (frames.Length > 0)
|
||||||
{
|
{
|
||||||
directives.Add($"frame-src {Join("'self'", frames)}");
|
// No 'self': a website that embeds only a third party (the captcha widget) frames nothing of its own.
|
||||||
|
directives.Add($"frame-src {Join(string.Empty, frames).Trim()}");
|
||||||
}
|
}
|
||||||
|
|
||||||
directives.AddRange(
|
directives.AddRange(
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ public sealed class SecurityHeadersOptions
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Origins added as a <c>frame-src</c> directive under the <c>StrictSite</c> policy only (for example the Friendly
|
/// Origins added as a <c>frame-src</c> directive under the <c>StrictSite</c> policy only (for example the Friendly
|
||||||
/// Captcha widget, which renders in an iframe: <c>https://global.frcapi.com</c>, <c>https://eu.frcapi.com</c>).
|
/// Captcha widget, which renders in an iframe: <c>https://global.frcapi.com</c>, <c>https://eu.frcapi.com</c>).
|
||||||
/// Empty (the default) adds no <c>frame-src</c> at all, so existing headers are unchanged.
|
/// Empty (the default) adds no <c>frame-src</c> at all, so existing headers are unchanged. The directive lists exactly these origins, without <c>'self'</c>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IList<string> AllowedSiteFrameOrigins { get; set; } = [];
|
public IList<string> AllowedSiteFrameOrigins { get; set; } = [];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user