aspnetcore-security-headers icon indicating copy to clipboard operation
aspnetcore-security-headers copied to clipboard

Alternative syntax

Open gatecrasher63 opened this issue 1 year ago • 1 comments

This is the normal syntax

        app.UseCsp(builder =>
        {
            builder.ByDefaultAllow
                .FromSelf();
        });

I need to be more flexible. How would I do this?

    var cspBuilder = new Joonasw.AspNetCore.SecurityHeaders.Csp.Builder.CspBuilder();
		
cspBuilder.ByDefaultAllow.FromSelf();

		if (cConfig.HashList != null)
		{
			foreach (var c in cConfig.HashList)
				cspBuilder.AllowStyles.From(c);
		}

    app.UseCsp( ???? )

what replaces ????

gatecrasher63 avatar Apr 04 '23 09:04 gatecrasher63

Is there something that prevents you from doing something like this?

app.UseCsp(builder =>
{
    builder.ByDefaultAllow
        .FromSelf();
    if (cConfig.HashList != null)
    {
        foreach (var c in cConfig.HashList)
            builder.AllowStyles.From(c);
    }
});

juunas11 avatar May 24 '23 05:05 juunas11