How to Audit Third-Party JavaScript on Your Website
Audit third-party JavaScript on your website in five steps: inventory every tag, record what it loads, watch for changes, and review who can edit it.
To audit third-party JavaScript on your website, build an inventory of every script tag and tag-manager container, record what each one loads and where it sends data, snapshot the code so you can detect changes, and review who can edit each vendor's configuration. The Optimizely incident of 16 November 2026 showed why this matters: 178 organizations served malware from a host they trusted, without any change to their own code, and most had no way to notice. This guide walks through the audit in five steps.
Why audit third-party JavaScript now
Scott Helme's point after the Optimizely incident is the whole case. Server-side code goes through source control, review, CI and approval before it reaches production. Third-party JavaScript goes through one step: add a script tag, and the browser runs whatever that URL serves, today and every day after. The URL never changes, but the content can, for a vendor feature, a vendor bug fix, or because an attacker edited it.
The Optimizely supply chain attack exploited exactly that gap. The attacker edited the Project JavaScript field inside customer projects, and the snippet at cdn.optimizely.com kept its URL, certificate and CDN while delivering a card skimmer, a crypto clipper and iOS exploit kits. Report URI found 188 infected snippets across 1,611 it checked. According to the HTTP Archive figure cited by KrebsOnSecurity, the median homepage loads at least 22 JavaScript files. Each one is a vendor whose compromise becomes yours.
Step 1: Inventory every tag
Start with what your own templates and tag managers load. Pull the list from three places:
- Page templates and layout components in source control. Search for script tags that point at external hosts.
- Your tag manager container. Export it and list every tag, trigger and the pages each trigger fires on. Tag managers are the most common way a marketing team adds a vendor without engineering noticing.
- The browser. Load each major page type (home, product, cart, checkout, account, login) with developer tools open and record every script request and its origin. This catches scripts that other scripts inserted, which the first two sources miss.
Record for each entry: the vendor, the URL, which pages it runs on, who in the organization owns it, and the business reason it exists. If nobody can state the reason, flag it for removal.
Step 2: Record what each script loads and contacts
A script tag is rarely one file. The Optimizely snippet inserted a second script from an attacker domain, which inserted a third from an .icu router domain, which opened an iframe. Your inventory needs the full chain for each vendor:
- Child scripts it inserts, and from which hosts
- Hosts it sends data to with fetch, XMLHttpRequest or sendBeacon
- Frames it opens
- Whether it reads form fields, the clipboard or cookies
The fastest way to collect this for every page at once is a Content Security Policy in report-only mode. The browser reports every script load, connection and frame that your draft policy does not already allow, from real visitors on real pages. The explainer on Content Security Policy covers how to set it up. Report URI's post on the incident notes that a report-only policy would have surfaced the new script dependency on 1688360.cc, the new data destinations card.php and hit.php, and the new frame source for the exploit kit, with nothing on the site breaking.
Step 3: Snapshot the code and watch for changes
Fetch each third-party script and store a copy with its hash and the date. Repeat on a schedule and diff. This is the step almost nobody does, and it is the one that would have shown the Optimizely change the hour it happened: Report URI's timeline is built from exactly this kind of evidence, including the Last-Modified header on Zoom's snippet at 11:20 UTC.
Expect noise. Experimentation and personalization vendors change their files whenever a customer edits an experiment, so a diff alert on the Optimizely snippet fires often. The useful signal is not "the file changed" but "the file now loads a host it never loaded before" or "the file now contains atob( or eval( where it did not." Report URI's guidance to Optimizely customers was to open every project's Project JavaScript and every experiment's custom code and look for the attacker domain, atob( and any code the customer did not write. Build that check into the diff review.
Subresource Integrity solves this completely for scripts that do not change: the browser compares the file's hash to the one in your script tag and refuses to run a mismatch. Apply it to every static vendor library. It cannot apply to dynamic snippets, which is why Steps 2 and 3 exist.
Step 4: Review who can edit each vendor's code
The Optimizely attacker did not need a customer password. The signup-flow flaw let them act as an administrator user on targeted accounts. That is a vendor-side failure, but it still surfaces the question every vendor relationship should answer: who, and what, can change the code that this vendor serves to our visitors?
For each vendor in the inventory, list:
- Named users with write access to the vendor dashboard, and whether each still needs it
- API tokens and integrations with write access, when they were created and what uses them
- Whether the vendor enforces MFA and SSO for your account
- Whether the vendor's product can run arbitrary custom code (Optimizely's Project JavaScript, a tag manager's custom HTML tag) and who can author it
Report URI's post-incident advice to customers was to review every user, API token and integration with write access to the Optimizely account and rotate credentials. Do that for every vendor, on a schedule, not only after a breach.
Step 5: Decide what stays and where it runs
An audit that ends in a spreadsheet changes nothing. Close it with three decisions per vendor: keep, remove, or restrict to specific pages. Optimizely's own guidance after the incident was to remove the Web Experimentation snippet from any page that handles payment or crypto input and that the customer is not running experiments on. Apply the same test to every tag. The case for keeping marketing tags off payment pages entirely is strong enough that it deserves a policy rather than a per-tag argument.
Then take the inventory to the Content Security Policy. Every host that survives the review goes in the policy. Every host that does not is now blocked, and the policy becomes the enforcement mechanism for the audit's decisions.
How do you find every third-party script on a site?
Combine three sources: a search of your templates and tag-manager container for external script tags, a browser developer-tools capture of every script request on each page type, and a report-only Content Security Policy that logs script loads from real visitors over several weeks. The first two give you the list you intended; the third finds the scripts that other scripts inserted and the pages you forgot.
How often should you re-audit third-party JavaScript?
Re-run the inventory quarterly and whenever marketing, product or engineering adds a vendor, and keep the change monitoring in Step 3 running continuously. Vendor compromises are measured in hours, as the Optimizely timeline shows, so a point-in-time audit catches the vendor list but not the attack.
What to check in Optimizely after 16 November
If the inventory includes the Web Experimentation snippet, Optimizely's report asks every customer, affected or not, to treat the event as a security incident. Confirm which pages the snippet ran on during the exposure window of 07:51 to 22:24 UTC on 16 November 2026, review CSP violation reports and outbound requests to unfamiliar domains in that window, review card and crypto transactions made on the site, and retain web server, CDN, WAF, CSP and fraud logs covering at least that day. Optimizely has withdrawn its early advice to disable the snippet and says it is safe to re-enable. Whether to re-enable it on checkout is your audit's decision, not the vendor's.