- A Content Security Policy (CSP) tells the browser which sources a page may load and execute. An A/B testing tool touches four directives: script-src, connect-src, frame-src and frame-ancestors.
- Experiments are defined after your page is deployed, so their code is not known when the CSP is written. Hashes and nonces only cover code that is known in advance. That is why tools that run custom variation JavaScript at runtime need
unsafe-evalin script-src. - Varify requires
unsafe-evalin script-src so that user-defined JavaScript can run within variations. The CSP can be configured per route, sounsafe-evalapplies only where experiments run. - Roll out the CSP in Report-Only mode first, check the reports, then enforce it. The list of Varify domains lives in the Varify documentation, in one place.
A Content Security Policy is an HTTP header that limits which scripts, connections and frames a page may use. It is one of the most effective defenses against cross-site scripting, and many security teams make it mandatory for every public website. An A/B testing tool has to fit into that policy, because it loads a script, talks to its own servers and changes the page while it runs.
This page is the decision page for a security review: which directives are involved, why runtime experiments need unsafe-eval, and how to keep that exception as narrow as possible. The exact domains Varify needs are listed in the Varify documentation under Content Security Policy error; this page links to that list and does not repeat it, so there is only one source to keep current.
Why A/B testing tools meet strict CSPs
A strict CSP assumes that every script on a page is known at deploy time. The policy either lists the allowed sources or pins each inline script with a hash or a nonce. Anything else is blocked.
A client-side A/B testing tool works the other way round. Your team creates an experiment in the tool's editor, often days after the page was deployed. The experiment can change text, swap images, move elements or run custom JavaScript. That code reaches the visitor's browser at runtime, as part of the experiment configuration, and the testing script executes it there.
Three consequences follow for the CSP:
- The testing script's own source has to be allowed in script-src.
- The requests the script sends, for example to load experiment configurations or to report events, have to be allowed in connect-src.
- Code that only exists at runtime cannot be pinned by a hash or nonce in advance. Executing it needs an exception in script-src.
The same constraint applies to any tool that executes custom variation JavaScript in the browser through eval-style functions.
Which directives are involved
Four directives decide whether an A/B testing tool works under your CSP. The Varify column links to the documentation, where the exact entries are kept.
| Directive | What it controls for an A/B testing tool | Varify entry |
|---|---|---|
script-src | Loading the testing script, and executing experiment code at runtime | See docs, including unsafe-eval |
connect-src | Requests from the script to the vendor's servers, for example experiment configurations and events | See docs |
frame-src | Frames the tool opens on your page, for example for editor features | See docs |
frame-ancestors | Whether your page may be shown inside a frame, for example by editor features | See docs |
Two further directives can matter depending on what your experiments do: img-src if variations load images from a new source, and style-src if variations add styles. Check them against the experiments your team plans to run.
Why runtime experiments need unsafe-eval
A CSP offers two ways to allow a specific script without allowing everything: a hash of the script's content, or a nonce, a random value the server sets for each response and repeats on each allowed script tag. Both work only for code the server knows when it sends the page.
Experiment code does not meet that condition. It is written in the testing tool, delivered as data, and turned into executable code in the browser. Neither a hash nor a nonce can be computed for it in advance. When that step uses eval or similar functions, the browser only allows it if script-src contains unsafe-eval.
Varify's documentation is explicit about it:
- "You also need the value unsafe-eval in the script-src directive."
- "Note: The unsafe-eval entry is necessary so that user-defined JavaScript can be executed within variations."
- "No, technically speaking, creating and delivering experiments isn't possible without
unsafe-eval."
The full explanation is in the documentation article Strict CSP does not allow unsafe evaluation. For your review, the relevant question is therefore how far the exception reaches.
How to limit the risk
unsafe-eval widens what a script on the page may do. The goal of the review is to keep that widening as small as possible. Three measures work together:
- A CSP per route. The CSP can be configured differently for each route, so
unsafe-evalapplies only where experiments run, for example on product and landing pages. Keep the strict policy on login, account and payment pages. A per-route policy narrows where the exception applies; pages of the same origin can still reach each other, so it does not replace the other two measures. - Report-Only first. Send the new policy as
Content-Security-Policy-Report-Onlyfor a period of normal traffic. The browser reports violations without blocking anything. Fix the policy until the reports only show what you expect, then switch to the enforcingContent-Security-Policyheader. Run the Report-Only period long enough to cover the experiments your team plans, because a page without a running experiment does not show what an experiment needs. - Control what goes into experiments. Decide internally who may publish variations with custom JavaScript, and review that code before it goes live. The CSP exception is only as safe as the process for the code that uses it.
Varify also offers first-party context on the Enterprise plan: "First-party context (CNAME): Deliver the Varify script from your own subdomain for better performance and fewer blockers." The setup is described on the page about first-party context (CNAME).
Varify's CSP requirements
The domains and directive values Varify needs are kept in one place, the Varify documentation. Use these two articles for your configuration:
- Content Security Policy error: the list of domains per directive, including the
unsafe-evalvalue in script-src. - Strict CSP does not allow unsafe evaluation: why experiments need it, and how to configure the CSP per route.
Varify's DPA lists "Provision of data via encrypted connections such as SFTP or HTTPS" among its technical measures.
For the rest of the security review, see the 25-point security checklist for A/B testing tools.
Checklist for the security review
Document these points in your review of any A/B testing tool:
- The vendor's CSP requirements are documented, per directive.
- The domains in
script-srcandconnect-srcare taken from the vendor's current documentation, with the date you checked it. - The reason for
unsafe-evalis documented, if the tool requires it. - The routes that allow
unsafe-evalare listed, and the routes that do not are listed. - Login, account and payment pages keep the strict policy.
- The policy ran in
Report-Onlymode before enforcement, and the reports were reviewed. - The internal rule for who may publish custom JavaScript in variations is written down.
frame-srcandframe-ancestorsare checked against the tool's editor features.- The decision is reviewed when the vendor changes its domains or when experiments move to new routes.
Talk CSP with our team
Bring your Content Security Policy to the demo and plan which routes run experiments.