Optimizely 4 min read

Your A/B Testing Script Can Read More Than the Button

Key takeaways

  • Third-party scripts embedded directly in a page can read its content and input fields.
  • A compromised script delivery path can expose visitors without changing the website’s own files.
  • Allowing a trusted domain does not guarantee that its scripts remain unchanged.
  • Sensitive pages deserve tighter limits on which external scripts can run.

Changing a signup button sounds like a small product decision. But the external code running that experiment may also be able to read the form beside it. The browser grants access based on how code runs, not what the marketing team hired it to do.

A small experiment, a broad permission

Services such as Optimizely help teams run A/B tests: show visitors different versions of a page, then compare their responses. Try a different button label. Measure which version gets more clicks.

To do that work in the browser, a script needs to inspect and modify the page. It may also need to observe interactions.

The catch is the gap between intended use and actual access. Asking a tool to change one button does not create a browser-enforced boundary around that button.

A script loaded directly into a page generally runs in that page’s execution environment, even when the file comes from an external server. It can read other content and inspect input values in the same document. Its modest assignment does not make its permissions modest.

Your server can be fine while visitors get malicious code

Consider a hypothetical online store that loads a testing script from an outside service. An attacker compromises the script’s delivery path and inserts malicious code.

The store’s own files could remain untouched. Visitors could still receive and execute the altered script when they open the page.

That is one form of a supply chain attack: malicious code arrives through a supplier the website already trusts.

But a supplier compromise does not automatically mean every customer or visitor was affected. The impact depends on which files changed, which pages loaded them, and whether a particular visitor received the malicious version.

Those distinctions matter when assessing an incident. Using a service, executing compromised code, and suffering a data leak are separate findings. Evidence for the first does not establish the other two.

A trusted address is not a guarantee about the file

Content Security Policy (CSP) lets a website set browser rules, including restrictions on where scripts can load from. Limiting those sources is useful.

An allowed source can still deliver an altered file, though. A domain allowlist establishes where code may come from; it does not verify that the code’s contents are unchanged.

Subresource Integrity (SRI) addresses that different problem. The website supplies an expected cryptographic hash—a fingerprint of the file—and the browser checks the downloaded resource against it. If they do not match, the browser blocks execution.

That introduces an operational tradeoff. When a legitimate script changes, its expected hash must change too. A testing service that frequently updates code as experiments change needs a workable process for managing those updates.

CSP and SRI therefore answer different questions: where may this script come from, and does this file match the version we expected? Treating them as interchangeable leaves gaps.

Give external code a reason to be on each page

The most useful starting question is straightforward: does this script need to run here?

Testing copy on a promotional page has different consequences from running code on a checkout page. The same tool can encounter very different information depending on where it executes.

A practical review should cover four things:

  • Placement: Check whether external scripts need to run on login, checkout, and account-management pages.
  • Purpose: Remove code for completed experiments and tools nobody uses anymore.
  • Isolation: Assess whether functionality can run inside a separate-origin frame with appropriate restrictions.
  • Shutdown: Confirm that the team can quickly disable the script if something goes wrong.

Isolation comes with limits. A tool contained in a separate frame may lose the access it needs to change the surrounding page or observe interactions. That tradeoff belongs in the decision to adopt the tool, alongside its features.

Every external script should have a reason to run on each page where it appears. Permission to change a button can also mean permission to read the form beside it.

Optimizely Supply Chain Attacks Web Security

Comments

    Loading comments...