Skip to content

Commit

Permalink
Add a more strict default
Browse files Browse the repository at this point in the history
  • Loading branch information
damienbod committed Oct 18, 2024
1 parent 8ecda56 commit dc4c9af
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static HeaderPolicyCollection Copy(this IReadOnlyHeaderPolicyCollection p
/// <summary>
/// Add default headers in accordance with the most secure approach
/// </summary>
/// <param name="policies">The <see cref="HeaderPolicyCollection" /> to add the deafult security header policies too</param>
/// <param name="policies">The <see cref="HeaderPolicyCollection" /> to add the default security header policies too</param>
/// <returns>The <see cref="HeaderPolicyCollection" /> for method chaining</returns>
public static HeaderPolicyCollection AddDefaultSecurityHeaders(this HeaderPolicyCollection policies)
{
Expand All @@ -51,6 +51,9 @@ public static HeaderPolicyCollection AddDefaultSecurityHeaders(this HeaderPolicy
builder.AddFrameAncestors().None();
});
policies.AddCrossOriginOpenerPolicy(x => x.SameOrigin());
policies.AddCrossOriginEmbedderPolicy(builder => builder.RequireCorp());
policies.AddCrossOriginResourcePolicy(builder => builder.SameOrigin());

return policies;
}

Expand Down Expand Up @@ -80,6 +83,12 @@ public static HeaderPolicyCollection AddDefaultApiSecurityHeaders(this HeaderPol
// The following are generally not applicable, but still worth applying for safety
policies.AddReferrerPolicyNoReferrer();
policies.AddPermissionsPolicyWithDefaultSecureDirectives();

policies.AddReferrerPolicyStrictOriginWhenCrossOrigin();
policies.AddCrossOriginOpenerPolicy(builder => builder.SameOrigin());
policies.AddCrossOriginEmbedderPolicy(builder => builder.RequireCorp());
policies.AddCrossOriginResourcePolicy(builder => builder.SameOrigin());

return policies;
}
}

0 comments on commit dc4c9af

Please sign in to comment.