When 3rd party JavaScript attacks
Simon Wijckmans from c/side joins Jerod & Nick to discuss the Pollyfill attack in detail. What does it mean for web developers & client-side security going forward?
Matched from the episode's transcript 👇
Simon Wijckmans: Well, in 2024 you probably should, I agree. But look back seven, eight years when people added that script to their website for the first time. This was a very real issue. So people added this script to their website. Andrew Betts, the open source contributor - he wrote the code, but he didn’t own polyfill.io. That was someone else. And that person in February this year somehow allowed a change of ownership to happen. I don’t know the details of how that happened, that is not publicly known, but there was a change of ownership and the domain name polyfill.io was purchased by a Chinese company.
And so that Chinese company didn’t do anything special with it for the first few months. On the main page of that domain they had a webpage that was saying “Yeah, this is just a polyfill package”, and all of that stuff. And obviously, the wider web community noticed that change of ownership, and it was quite weird… And then of course, the open source contributor that wrote the package originally posted about it on Twitter… Some alarm bells started going off and there were a few mirrors available at that point. So Fastly and Cloudflare did blog posts about it, and they made a mirror available of that package on their own CDN. And that then triggered, funny enough, the Chinese owner of that domain to change their website and say “Protected by Cloudflare”, which I found a rather interesting detail. If you go on the Wayback Machine, you can still see that header.
[06:08] The way that then things evolved over time is all of a sudden on the 25th of June certain users, depending on their user agent, would see that script, and that script would also include a third-party script itself pointing to googleanaiytics.com. So it was Google Analytics where the L was changed to an I. And that was then another malicious script that was known to redirect people to adult content websites and online casinos.
This is, in my opinion, an incredibly juvenile attack, because there’s really not a lot you gain from that. Perhaps some ad revenue through generating click-through… But there’s not really any big money being made here. And they also made it so that this attack only occurs on the initial requests. So when you refreshed that same website you went to, you wouldn’t be redirected to that same adult content site or casino… So it became harder to debug.
The thing is that the bad actor could have pulled off a way worse attack. They could have listened in on keystrokes, and exfiltrated that, and only made that action happen in a small percentage of requests, from specific regions, on a certain time schedule, and probably fly below the radar for months. Because the reality is that most websites do not have client-side security in place. So whatever a third-party script does, they’re just able to do, and they’re not really keeping an eye on it.
That kind of brings us to the bigger problem here… We do a lot to protect our own infrastructure. We put all types of interesting firewalls, by all types of really senior and well-known companies in front of our own infrastructure to protect our infrastructure against inbound attacks… We spend money on protecting our supply chain, or better said, parts of the supply chain, so those that live on registries… And there’s some really amazing companies out there that do a really good job at that. But then we still allow people to do things completely dynamically client-side. And we don’t actually know what people are getting in a browser of a user. And that, in my opinion, is a big part of supply chain. And it shouldn’t be sort of an entirely different subject, but the reality is that as we protect our open source dependencies, as we protect our infrastructure, bad actors will, of course, always look for a way to make themselves rich and make themselves successful in their careers… And therefore, executing attacks in a browser of a user is sort of a logical next step.
And so this polyfill attack was one of those examples where we just had to make a lot of noise as a community, to make this a known thing. In fact, if you were to go back to some of those posts back then, you’ll see that we were being referenced a lot. We were one of the companies to notice it as a first. And then we put a lot of blog posts out, I put our PR people on it, they then got all of these media outlets to write about it… So for some time, people were aware of the risk. There is a real risk that we’ve gone back to a world where people don’t know about risk, and they just kind of accepted it, and was like “This is a one-off.” Reality is, this is not a one-off. Most websites still have over 20 of these, many websites have over 50 of them. Third-party scripts are completely dynamic. They can act completely differently from what you think. Even if you think they’re static, there’s nothing really stopping them from acting dynamically… Unless, of course, if you add a hash to your script tag, which unfortunately people don’t do that often.