Content-Security-Policy header, the browser will block the ShieldLabs snippet unless you add its hosts to your allowlists. The snippet loads its modules from the ShieldLabs CDN and sends the collected signals to a few shieldlabs.ai endpoints. Each of those needs a directive.
If you have not added the snippet yet, start with Add the snippet and come back here once it loads.
Required directives
Add these two directives to your existing policy. Merge the hosts into directives you already have rather than duplicating them.What each host is for
script-src covers the code that runs. connect-src covers where the snippet sends data.
All ShieldLabs code loads from
https://cdn.shieldlabs.ai, so script-src needs that one host. The shieldlabs.ai data endpoints belong in connect-src because the snippet connects to them to send data.The snippet loads code by dynamic
import() only, so it runs under a policy without 'unsafe-eval'.Inline scripts: HTML method vs framework method
The two install methods from Add the snippet have different inline-script requirements.- HTML script tag (needs inline)
- Framework component (no inline)
The HTML method runs an inline Because the bootstrap code is inline, a policy that forbids inline scripts will block it. You have two options:
<script type="module"> that calls import():- Move the bootstrap into an external module file you serve from
'self'(no inline code), or - Use the framework component method instead (next tab), which has no inline script at all.
'unsafe-inline' if you can. The framework method removes the need for it entirely.Full-header examples
Drop these into your stack and adjust the surrounding directives to match your app. Only the two ShieldLabs directives are required.If a connection is blocked
Ifconnect-src omits https://rest.shieldlabs.ai, the snapshot cannot post and no identification is recorded. If it omits https://webrtc.shieldlabs.ai, the identification still posts and is scored, but the network check cannot complete, and those identifications can carry the stun_not_checked risk signal (weight 30), which on its own puts a real user in the Suspicious band. Keep every host above in your policy.
Verify it works
After deploying your policy:1
Load a page with the snippet
Open a page where the snippet runs and open your browser’s developer tools.
2
Check for CSP violations
A blocked host shows a
Refused to load or Refused to connect error naming the directive and the host. If you see one, add that host to the directive it names.3
Confirm the snapshot posted
In the Network tab, confirm a request to
rest.shieldlabs.ai succeeded. Once it does, ShieldLabs scores the identification and delivers your webhook.Related
- Add the snippet: the HTML and framework install methods these directives support.
- API keys: the Public Key that goes in the snippet URL.
- Webhooks: where the Risk Score and risk signals arrive after the snapshot posts.