April 2018
Intermediate to advanced
300 pages
7h 41m
English
The Content-Security-Policy header protects your application by whitelisting the sources of approved content and preventing the browser from loading malicious resources. This can be added by adding the NWebsec.Owin package from NuGet and defining it in the Configure method of the Startup class as follows:
app.UseCsp(options => options.DefaultSources(s => s.Self()).ScriptSources(s => s.Self()));
In the preceding code, we have mentioned the DefaultSources and ScriptSources to load all the resources from the same origin. If there are any scripts or images that need to be loaded from external sources, we can define the custom sources as follows:
app.UseCsp(options => options .DefaultSources(s => s.Self()).ScriptSources(s ...