Content-Security-Policy header
Veva adds a Content-Security-Policy header to every page. A resource from another domain (an image, a stylesheet, a script, a font) loads only when that domain is allowed: in the website's Advanced Settings, or from code in a page request hook.
The header (MDN: Content Security Policy) tells the browser which sources a page may load from. Veva builds it from the website's settings on each request, and the browser blocks anything it does not allow. Veva's own modules and the integrations allow what they need themselves. A site that links to other domains by hand, say a web font or an embed, has to allow them.
Allow a domain in the website's settings
In the website's Advanced Settings, under Http security, add the domain to Custom CSP values. Give the full domain with its scheme (https://fonts.gstatic.com) and the type of source: Scripts, Styles, Images, Fonts, Media, Frames, Workers or Connect. No code and no deploy are needed.
The same group holds the switches for the header itself:
- Disable the automatically generated CSP header turns it off.
- Disable unsafe-inline for scripts and Disable unsafe-inline for styles take
'unsafe-inline'out ofscript-srcandstyle-src. Both are allowed until you switch them on. - Use nonce for scripts adds a nonce to
script-srcand to the page's script tags.
Allow a domain from code
A module can add sources in an IPageRequestHook (Veva.Core.Domain.Interfaces). pageRequest.SecurityOptions holds a list per directive: ScriptResources, StyleResources, ImageResources, FontResources, MediaResources, FrameResources, WorkerResources and ConnectResources. Veva writes the header in a hook with OrderIndex 1100, so give yours a lower one.
public class CustomCspSources : IPageRequestHook { public int OrderIndex => 1000; public Task OnRequestAsync(PageRequest pageRequest) { pageRequest.SecurityOptions.FontResources.Add("https://fonts.gstatic.com"); pageRequest.SecurityOptions.StyleResources.Add("https://fonts.googleapis.com"); return Task.CompletedTask; } }
Register it in your module's ConfigureServices:
services.AddScoped<IPageRequestHook, CustomCspSources>();
Fonts
A web font service often needs its domains under both Fonts and Styles: the stylesheet comes from one host and the font files from another. Open the browser console on the page to see what was blocked, and add those domains.