Skip to main content
If your site sets a Content-Security-Policy header, you need to allow the Foil SDK to load, execute WebAssembly, spawn inline workers, create probe iframes, and communicate with the Foil API.

Required directives

script-src

The SDK is loaded as an ESM module from the Foil CDN. It also contains an embedded WebAssembly module that requires 'wasm-unsafe-eval' to instantiate.
'wasm-unsafe-eval' is the standard keyword for allowing WebAssembly to compile without also allowing eval() and other string-to-code APIs. 'wasm-eval' isn’t a standard keyword, so use 'wasm-unsafe-eval'.

connect-src

The SDK sends encrypted observation data and receives scoring results from the Foil API, and runs the network edge probe against Foil’s probe zone.

worker-src

The SDK creates inline Web Workers from blob URLs for cross-thread environment validation and debugger detection.

frame-src

The SDK creates temporary hidden same-origin iframes for realm isolation probes, CSP bypass detection, and font measurement.

WebRTC traffic

Two probes use WebRTC, and their UDP traffic goes only to Foil’s probe hosts: connect-src and default-src don’t apply to WebRTC, so your policy needs no entry for these STUN and ICE connections. The network edge probe’s HTTPS and WebTransport requests are covered by https://*.e2.usefoil.com in connect-src. If a firewall blocks outbound UDP to these ports, the fingerprint probe reports only the candidates the browser gathers locally, and the network edge probe still completes over HTTPS but without its WebRTC and WebTransport measurements.

Full example

A minimal CSP that supports Foil alongside your own assets:
Foil itself needs no font-src - it measures font metrics in place and fetches no external fonts. Add font-src only for your own web fonts.
If you use a meta tag instead of a response header:

First-party integrations

If you serve Foil from your own domain through a first-party integration, the SDK loads t.js and sends collection requests to the integration URL instead of cdn.usefoil.com and api.usefoil.com. Allow the integration’s origin in script-src and connect-src. The network edge probe still connects to Foil’s probe zone directly, so keep it in connect-src. Step 4 of the integration page shows the exact script-src and connect-src lines for your integration next to the install snippet. For an integration at https://www.example.com/foil on a page served from https://www.example.com, 'self' already covers the integration origin:
When the integration URL is on a different origin from the page, such as https://app.example.com loading from https://www.example.com/foil, list it explicitly:
Remove https://cdn.usefoil.com and https://api.usefoil.com only when no page on your site loads the SDK directly. If you use verifyHuman(), keep https://cdn.usefoil.com in script-src, https://api.usefoil.com in connect-src, and https://human.usefoil.com in frame-src: human verification always loads from and talks to Foil directly. The worker-src directive doesn’t change.

Allow the install snippet

The install snippet’s module script is inline. A policy whose script-src doesn’t include 'unsafe-inline' blocks it, even when the policy allows the integration origin. Allow it in one of three ways. The snippet’s modulepreload link needs no nonce or hash, because script-src already allows the integration origin. If your policy uses 'strict-dynamic', which ignores origins, give the link the same nonce as the script.

Use a nonce

Generate a new random nonce for every response, add it to script-src, and set the same value on the <script> element:
Never reuse a nonce across responses, and don’t cache a page whose HTML contains one.

Use a hash

Add the SHA-256 hash of the script’s exact contents, everything between <script type="module"> and </script>, to script-src:
Compute the hash with openssl, where snippet.js holds the script’s contents byte for byte, including whitespace:
The hash changes whenever the snippet’s contents change, including its whitespace and the publishable key, so update the policy whenever you change the snippet.

Load it from a file

Save the module script’s contents as a module file on your site, such as /foil.js, and load it with a src attribute. 'self' in script-src then covers it, and the policy needs no nonce or hash. Keep the modulepreload link for t.js in the page:

Roll out the policy

Deploy a new or changed policy with the Content-Security-Policy-Report-Only header first, with a report-to or report-uri endpoint. The browser then reports violations without blocking anything. Load pages that run the install snippet, confirm that no reports name the snippet, the integration URL, or *.e2.usefoil.com, then send the same policy as Content-Security-Policy.

Graceful degradation

The SDK is designed to degrade gracefully. If a CSP directive blocks a specific probe (e.g., workers or iframes), the SDK will skip that signal and continue with the remaining detection surface. However, missing signals reduce coverage and may affect verdict confidence. For best results, allow all directives listed above.

What Foil does NOT need

Troubleshooting

Check the browser DevTools console for CSP violation errors. Common failures:
If you use a CSP reporting endpoint (report-uri or report-to), deploy in report-only mode first with Content-Security-Policy-Report-Only to catch violations without breaking the page.