TL;DR / Geek Summary:
- Incident: Detected a domain hijacking the entire blog via Cloudflare Workers reverse proxy.
- Defensive Patch: Implemented a JavaScript domain validator in the
<head>to force redirects.- Obfuscation Hack: Used obfuscator.io to encrypt the JS logic, preventing the proxy from rewriting validation rules.
Yesterday, I was checking my Google Analytics data in my free time and spotted a referral from a domain I had never seen before. Initially, I thought it was just a scraper site or someone referencing my article, so I decided to take a look. However, upon opening the page, I saw my entire blog right there (completely unmodified).
I wouldn’t just say the content was identical; even the page structure was exactly the same. I’ve seen scrapers and I’ve seen people referencing my work, but I’ve never seen an entire site being reverse-proxied like this before…
# At First
At first, I thought they had just scraped and downloaded the site, and I wasn’t going to care. But later I realized they were directly reverse proxying it using Cloudflare Workers, and they had even modified the host header. Because of this, standard anti-hotlinking measures were basically useless…
After some Googling, I found out that this kind of situation can be handled using a JavaScript script.
In the beginning, I just used JS to verify if the window’s domain was correct. If it wasn’t, it would automatically redirect to the correct domain.
The code is as follows. Please put it inside the <head> tag:
| |
However, this guy didn’t play by the rules. Through the reverse proxy, he replaced all the domains in the files with his own domain, which resulted in an infinite loop.
Later, I used https://obfuscator.io/ to obfuscate the JS code. This successfully prevented the domains from being modified and replaced.
The obfuscated sample code is as follows:
| |
By taking this encrypted code and randomly inserting it into one of the scripts referenced on your site, you’ll leave the trash running those mirror sites with no way to bypass it.
With this, the problem is basically solved. Let those jerks go cry about it.
