Lesson 10 of 14 · 12m
Third-Party Scripts Are Remote Code
A script tag hands your origin to a remote operator — polyfill.io's 2024 sale and the Magecart skimming of British Airways as the evidence.
A script tag is a privilege grant
<script src="https://cdn.example/widget.js"> does not embed a feature; it hands a remote operator your origin. The fetched code executes with everything your own code gets: the DOM, document.cookie (HttpOnly only stops JS, and plenty of tokens are not HttpOnly), fetch as the user, localStorage, form fields as users type them, and the ability to rewrite or redirect the page itself.
There is no per-script sandbox. No "read-only" script load. The security posture of every host named in script src becomes part of your attack surface, and the code they serve changes without touching your repository — so the payload never appears in your diffs, your reviews, or your tests. new Worker(url) and importScripts(url) are the same grant through a different door; CSP's worker-src exists precisely because people forget workers are remote code too.
The wrong mental model is "it is just a library, libraries are vetted." Libraries are code someone else can change tonight.
polyfill.io: the CDN that sold itself
cdn.polyfill.io served JavaScript polyfills to a large fraction of the web. In February 2024 the maintainer sold the domain and GitHub account to Funnull, a Chinese company. Security folks flagged the sale immediately; by June 2024 Sansec documented what the new owner was serving: injected code that redirected mobile visitors of embedding sites to scam and betting domains through fake googie-anaiytics.com loaders. Over 110,000 websites carried the payload, including properties belonging to Intuit and the World Economic Forum.
The payload was professionally evasive — it activated only on specific devices at specific hours and went dormant when it detected an admin user or analytics instrumentation. Namecheap suspended the domain on June 26, 2024; Cloudflare and Fastly stood up clean mirrors so sites could swap without rebuilding. The incident is the canonical proof that a script tag is a live wire: nothing about the embedding sites changed, nothing needed to be hacked — the trust they had already granted was simply exercised by its new owner.
British Airways: the first-party version
Magecart's August–September 2018 skimming of British Airways needed no CDN at all. Attackers modified modernizr-2.6.2.min.js — a first-party file served from ba.com — appending a 22-line card skimmer that watched the baggage-payment form in the site and the app. Somewhere between 380,000 and 500,000 payment transactions were skimmed. The ICO proposed a £183.4 million fine; the final penalty settled at £20 million in October 2020.
Self-hosting is necessary but not sufficient. The file was on BA's own infrastructure; what failed was integrity — nothing verified the bytes being served were the bytes anyone intended. That is precisely what Subresource Integrity pins (lesson 11) and why CSP reports belong on your own hosts too. Magecart ran the same play across thousands of stores for years — formjacking and injected skimmers on checkout flows — and the common denominator was never an exotic exploit. It was always a script the site already trusted being quietly changed underneath it.
What to actually do
- Enumerate every
<script src>andnew Worker(...)on your pages. Each is a trust grant; write down why it exists. - Prefer self-hosting vendored copies of static libraries over third-party hot-links — your own origin under your own deployment controls.
- Where a CDN is justified, use immutable versioned URLs plus SRI hashes (lesson 11), never mutable
latestendpoints. - Keep
script-srctight, but understand its limit from lesson 9: a host allowlist does nothing when the allowed host is the one compromised. CSP gates the address; SRI gates the bytes. - Revisit analytics and chat pixels periodically. They carry identical privileges to an attacker's payload; each one should still be earning its keep.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
They Got Root on a Fully Patched Ivanti VPN and the Integrity Checker Said Everything Was Fine
Volexity caught an attacker chaining zero-days into unauthenticated root on an Ivanti Connect Secure appliance running the latest build. The payload never touched disk, commands rode in over the same HTTPS requests as the exploit, and Ivanti's Integrity Checker reported no modifications.
Gitea Shipped 21 CVEs in One Release and Eleven of Them Are the Same Bug
Gitea 28.3.0 landed November 1 with twenty-one CVE fixes. Read the list and a pattern jumps out: more than half are the same failure repeated across different route handlers, where a token scoped to public data gets handed private data anyway. That's not twenty-one mistakes.
php2shell: The PHP Bug That Fires Before Your Code Runs
Two critical PHP flaws landed October 21 and were in CISA's exploited-vulnerabilities catalog five days later. The 9.2 score isn't the part that should bother you. It's where the bug lives — it goes off while PHP is still assembling $_POST, before a single line of your application has run.
A Certificate Authority's Private Keys Were the Numbers 4, 56 and 66
Eight eMudhra intermediate CA keys turned out to be recoverable from their own public certificates. Not stolen — computable, because the key generation produced almost no entropy. A researcher pulled all eight in under a second and signed a message with each one to prove it.