Private Client · Europe
Polyfill.io and the CDN Supply Chain: How We Audited 200 Sites in 48 Hours
When the Polyfill.io domain turned malicious after a Chinese company bought it, 100,000+ websites became attack vectors. Here's how we audited and fixed 200 sites in 48 hours.
Measured results
- Scanned 200+ web properties in 48 hours
- Found and fixed Polyfill.io references on 47 sites
- Implemented Content Security Policy across all properties
- Built ongoing third-party script monitoring
Challenge
The blocker
When the Polyfill.io supply chain attack hit 100,000+ websites, one of our clients — a media company with 200+ web properties — needed to know which of their sites were affected and how to fix them before the weekend.
Solution
The approach
We built an automated scanner that checked all 200 sites for Polyfill.io references, replaced them with Cloudflare's mirror, and implemented a CSP policy to prevent future unauthorized script loading.
Execution story
In February 2024, a Chinese company called Funnull acquired the polyfill.io domain and its GitHub account. The original creator, Andrew Betts, had concerns immediately — the new owner had no track record in the open source community, and a supply chain risk was obvious to anyone paying attention.
Four months later, in June 2024, those concerns were confirmed. Security firm Sansec discovered that the polyfill.io domain was injecting malicious JavaScript into mobile devices on any website that embedded cdn.polyfill.io. Over 100,000 websites were affected, including major brands like Intuit and the World Economic Forum.
"The polyfill code is dynamically generated based on the HTTP headers, so multiple attack vectors are likely. The code was deliberately designed to mask the redirections by performing them only at certain times of the day and only against visitors who met specific criteria." — Sansec, June 2024
One of our clients — a media company with 200+ web properties — used Polyfill.io on many of their sites. They called us on Wednesday. They needed all sites checked and fixed by Friday.
The scale of the problem
Polyfill.io was popular because it was easy: drop a <script> tag in your HTML, and older browsers got the JavaScript polyfills they needed. No build step, no npm package, no maintenance. For a media company with 200+ properties built over 10 years by different teams, that convenience meant the script was everywhere.
But it wasn't just in HTML. It was in:
- Direct
<script>tags in HTML files - WordPress themes and plugins (dozens of them)
- Tag manager containers (Google Tag Manager, Tealium)
- Third-party widgets that loaded their own scripts
- Cached HTML on CDN edges
A simple grep of the codebase wasn't enough. We needed to check what was actually being served, not just what was in the source.
The 48-hour audit
Hour 0-6: Build the scanner
We wrote an automated scanner that checked each of the 200+ properties by:
- Fetching the rendered HTML (not just the source — the DOM after JavaScript execution)
- Checking all
<script>src attributes forpolyfill.io - Checking inline scripts for dynamic
polyfill.ioloading - Checking CSP headers for
polyfill.ioin allowed origins - Logging results to a central dashboard
The scanner ran in parallel across all properties and completed the first pass in 47 minutes.
Hour 6-12: Triage
Results: 47 of 200+ properties had active polyfill.io references. Of those:
| Source | Count | Fix Complexity |
|---|---|---|
Direct HTML <script> tags | 18 | Low — replace the URL |
| WordPress themes/plugins | 15 | Medium — update or replace the plugin |
| Tag manager containers | 9 | Low — update the container config |
| Third-party widgets | 5 | High — contact the widget vendor |
Hour 12-36: Fix
For the direct HTML references, we replaced cdn.polyfill.io with cdnjs.cloudflare.com/polyfill/ — Cloudflare's mirror that serves the same polyfill content from a trusted source. This was a non-breaking change.
"All website owners, regardless of whether the website is using Cloudflare, should do this now." — Cloudflare, on replacing polyfill.io links
For the WordPress sites, we updated the themes and plugins that embedded Polyfill.io. Three plugins had no update available, so we replaced them with alternatives.
For the tag manager containers, we updated the container configurations to use the Cloudflare mirror. No code changes needed.
For the third-party widgets, we contacted the vendors. Two responded within 24 hours and pushed fixes. Three didn't respond, so we replaced those widgets with alternatives.
Hour 36-48: Prevent
We implemented a Content Security Policy (CSP) on all properties that explicitly allowed only trusted script sources. Any script from an unapproved domain would be blocked by the browser. This wouldn't have prevented the Polyfill.io attack (the domain was previously trusted), but it would catch future cases where a previously-trusted domain goes rogue.
We also set up ongoing monitoring: a daily scan of all properties for any new third-party script sources, with alerts for anything not on the approved list.
The broader lesson
The Polyfill.io attack is a textbook example of a supply chain risk that's hard to defend against. The domain was legitimate for years. The original author was trustworthy. The code was open source. And then the domain was sold to someone who wasn't trustworthy, and the code changed.
"384,773 sites continued to link to the site a week after malicious behavior came to light." — Ars Technica, July 2024
The defenses that work against this class of attack are:
- Minimize third-party dependencies. Every external script is a supply chain risk. If you don't need it, remove it.
- Self-host when possible. If you can host the script yourself, you control it. The trade-off is maintenance, but for critical sites, it's worth it.
- Use Subresource Integrity (SRI). SRI lets you specify a hash of the expected script content. If the content changes, the browser blocks it. This would have caught the Polyfill.io change.
- Monitor what's actually being served. Source code checks aren't enough. You need to check the rendered DOM, because scripts can be injected by tag managers, widgets, and other runtime mechanisms.
- Have a CSP. A Content Security Policy won't prevent every attack, but it limits the blast radius.
The numbers
| Metric | Value |
|---|---|
| Properties scanned | 200+ |
| Properties with Polyfill.io | 47 |
| Time to full scan | 47 minutes |
| Time to full remediation | 48 hours |
| Ongoing monitoring | Daily, all properties |
| CSP implemented | All properties |
What we learned
The client's team was competent and well-resourced. The problem wasn't capability — it was visibility. They didn't know Polyfill.io was on 47 of their sites because it had been added by different teams over many years, and nobody had a central inventory of third-party scripts.
The scanner we built became a permanent tool. It runs daily now, checking every property for every third-party script source and alerting the team when something new appears. The next time a popular CDN goes rogue — and there will be a next time — they'll know within 24 hours, not when a security firm publishes a blog post.