Content Security Policy for A/B Testing Tools: What IT Needs to Allow and Why

·Updated October 2026
CSP requirements documented in the Varify docs
unsafe-eval can be limited to the routes that run experiments
Enterprise: script delivery from your own subdomain
Key Takeaways
  • 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-eval in script-src.
  • Varify requires unsafe-eval in script-src so that user-defined JavaScript can run within variations. The CSP can be configured per route, so unsafe-eval applies 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.

DirectiveWhat it controls for an A/B testing toolVarify entry
script-srcLoading the testing script, and executing experiment code at runtimeSee docs, including unsafe-eval
connect-srcRequests from the script to the vendor's servers, for example experiment configurations and eventsSee docs
frame-srcFrames the tool opens on your page, for example for editor featuresSee docs
frame-ancestorsWhether your page may be shown inside a frame, for example by editor featuresSee 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:

  1. A CSP per route. The CSP can be configured differently for each route, so unsafe-eval applies 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.
  2. Report-Only first. Send the new policy as Content-Security-Policy-Report-Only for 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 enforcing Content-Security-Policy header. 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.
  3. 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:

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-src and connect-src are taken from the vendor's current documentation, with the date you checked it.
  • The reason for unsafe-eval is documented, if the tool requires it.
  • The routes that allow unsafe-eval are listed, and the routes that do not are listed.
  • Login, account and payment pages keep the strict policy.
  • The policy ran in Report-Only mode before enforcement, and the reports were reviewed.
  • The internal rule for who may publish custom JavaScript in variations is written down.
  • frame-src and frame-ancestors are 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.

Frequently asked questions about CSP and A/B testing

Does Varify work with nonces or hashes?

Nonces and hashes cover code that is known when the page is sent. Experiment code is created later and executed at runtime. Varify's documentation states: "No, technically speaking, creating and delivering experiments isn't possible without unsafe-eval." See Strict CSP does not allow unsafe evaluation.

Can we allow unsafe-eval only on some pages?

Yes. The CSP can be configured differently for each route, so unsafe-eval is allowed only on the pages that run experiments, and the strict policy stays everywhere else.

Which Varify domains belong in our CSP?

The current list is in the Varify documentation under Content Security Policy error. It is kept there only, so that your configuration always follows one source.

Why does the visual editor need frame-src?

Some editor features show your page inside a frame or open a frame on top of it. Depending on how a tool does this, your CSP has to allow the frame in frame-src, or allow your page to be framed in frame-ancestors. Which Varify feature needs these entries, and which values to set, is listed in the CSP documentation.

What should a security reviewer document about unsafe-eval?

The reason it is needed, the routes where it is allowed, the routes where it is not, the Report-Only period and its results, and the internal rule for who may publish custom JavaScript in variations. Review the decision again when experiments move to new routes.