Skip to content

Commit 2c23a47

Browse files
committed
Update security headers performance
1 parent 56d373f commit 2c23a47

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

bff/server/SecurityHeadersDefinitions.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@
22

33
public static class SecurityHeadersDefinitions
44
{
5+
private static HeaderPolicyCollection? policy;
6+
57
public static HeaderPolicyCollection GetHeaderPolicyCollection(bool isDev, string? idpHost)
68
{
79
ArgumentNullException.ThrowIfNull(idpHost);
810

9-
var policy = new HeaderPolicyCollection()
11+
// Avoid building a new HeaderPolicyCollection on every request for performance reasons.
12+
// Where possible, cache and reuse HeaderPolicyCollection instances.
13+
if (policy != null) return policy;
14+
15+
policy = new HeaderPolicyCollection()
1016
.AddFrameOptionsDeny()
1117
.AddContentTypeOptionsNoSniff()
1218
.AddReferrerPolicyStrictOriginWhenCrossOrigin()

0 commit comments

Comments
 (0)