How to Detect Malicious JavaScript Injection in Archived Web Pages

How to Detect Malicious JavaScript Injection in Archived Web Pages
Photo by Tara Winstead on Pexels

How to Detect Malicious JavaScript Injection in Archived Web Pages

The r/Seattle moderation team just dropped a bombshell: they’ve banned archive.today links after discovering what appears to be malicious JavaScript injection. When users visited archived pages, unexpected code was executing in their browsers—code that wasn’t part of the original archived content. This isn’t just subreddit drama; it’s a textbook example of why every IT professional needs practical skills to detect and analyze suspicious JavaScript behavior in the wild.

Whether you’re managing enterprise infrastructure, conducting security reviews, or just trying to protect your team from supply chain attacks, the ability to spot injected scripts is essential. Let’s turn this trending incident into a hands-on lesson in defensive techniques you can use today.

Table of Contents

What Actually Happened with Archive.today

Archive.today (also known as archive.is) is a popular web archiving service that Reddit communities use to preserve content that might disappear or change. The Seattle subreddit moderators noticed something off: archived pages were serving JavaScript that didn’t match the original source. This type of injection can enable everything from cryptocurrency miners to credential harvesters, and it’s particularly insidious because users trust archived content to be static and safe.

The moderators took the smart defensive posture—ban first, investigate later. But how would you verify this claim yourself? That’s where practical detection skills come in. If you’re building your cybersecurity expertise, platforms like Coursera offer hands-on courses in web security fundamentals that complement the real-world techniques we’re covering here.

Why JavaScript Injection Attacks Matter

JavaScript injection isn’t new, but it’s remarkably effective. Modern web applications trust JavaScript implicitly—it powers everything from form validation to entire single-page applications. When an attacker can inject their own script into a trusted context, they inherit all the privileges of that page. This means access to cookies, localStorage, session tokens, and the ability to manipulate the DOM to phish credentials or redirect users.

Third-party services like archiving sites, CDNs, and analytics providers represent a massive attack surface. If you’re using external scripts in your production environment, you’re trusting not just that provider today, but every future version of their code. One compromised CDN can inject malicious code into thousands of sites simultaneously.

⚠️ Common Mistake: Many developers assume that HTTPS alone protects against injection. It doesn’t. HTTPS ensures the content comes from the claimed server, but if that server itself is compromised or malicious, encrypted delivery just means you’re securely receiving malicious code.

Detecting Injected Scripts with Browser DevTools

Let’s get practical. Your first line of defense is your browser’s developer tools. Every major browser includes a network inspector that shows exactly what resources loaded and where they came from. Here’s how to conduct a basic injection audit:

Open your browser’s DevTools (F12 in most browsers), navigate to the Network tab, and reload the suspicious page. Filter for JavaScript files specifically. You’re looking for scripts loaded from unexpected domains or inline scripts that seem out of place.

// In Chrome DevTools Console, list all script sources on current page
Array.from(document.scripts).map(s => s.src || 'inline script').forEach(src => console.log(src));

This one-liner extracts every script element from the DOM and logs its source URL. External scripts will show their full URL; inline scripts will be labeled as such. Run this on both the original page and the archived version. Differences are your first red flag.

But sophisticated injection doesn’t always add new script tags—it might modify existing ones or inject code into legitimate-looking files. That’s where comparing content hashes becomes critical. If you have access to the original page’s scripts, you can verify integrity using Subresource Integrity (SRI) checking.

Comparing Script Content Hashes

When you suspect a specific script has been modified, generate its SHA-384 hash and compare it against the known-good version:

# Generate SHA-384 hash of a JavaScript file (Linux/Mac)
curl -s https://example.com/script.js | openssl dgst -sha384 -binary | openssl base64 -A

If the hashes don’t match, you’ve confirmed modification. In an enterprise setting, you’d automate this comparison as part of your security monitoring pipeline. Learning to build these validation workflows is exactly the kind of practical skill covered in security-focused training programs on platforms like DataCamp, where hands-on labs let you practice techniques in safe environments.

Using Content Security Policy as a Defense Layer

Detection is reactive. Content Security Policy (CSP) is proactive. CSP is an HTTP header that tells browsers which sources of content are legitimate for your page. If injected JavaScript tries to load from an unauthorized domain, the browser blocks it—even if the injection succeeded at the HTML level.

A basic CSP header looks like this:

Content-Security-Policy: default-src 'self'; script-src 'self' https://trusted-cdn.com; object-src 'none';

This policy says: “By default, only load resources from my own domain. For scripts specifically, allow my domain and trusted-cdn.com. Block all plugins entirely.” It’s not foolproof—inline scripts require additional configuration—but it dramatically reduces the attack surface.

The archive.today situation illustrates why CSP matters even for content you don’t control. If you’re embedding third-party content (archives, social media embeds, ad networks), CSP provides a boundary. You can use the sandbox attribute on iframes combined with CSP to isolate potentially dangerous content.

💡 Pro Tip: Start with CSP in report-only mode. Use the header Content-Security-Policy-Report-Only to see what would be blocked without actually blocking it. This lets you fine-tune your policy before enforcement, avoiding breaking legitimate functionality.

Automated Monitoring for Production Environments

Manual inspection works for investigating specific incidents, but enterprise environments need continuous monitoring. Modern security teams deploy tools that baseline normal JavaScript behavior and alert on anomalies. This includes tracking which external domains your pages load scripts from, monitoring for new inline script blocks, and comparing script content against known-good versions.

For smaller teams without dedicated security operations centers, browser extension frameworks like Tampermonkey can run automated checks. You can write a simple userscript that logs all script sources whenever you visit pages from specific domains, building your own lightweight monitoring solution.

The key is establishing a baseline. What scripts normally load? From which domains? What’s their typical size and hash? Deviations from this baseline trigger investigation. This is exactly how the r/Seattle mods likely noticed the problem—someone saw scripts they didn’t recognize on archived pages they’d used before without issue.

Key Takeaways for IT Teams

The archive.today incident isn’t just a cautionary tale—it’s a practical exercise in defensive security. Here’s what you should implement immediately:

Trust but verify external content. Even reputable services can be compromised or change their behavior. Archive services, CDNs, and analytics providers all represent third-party code execution in your users’ browsers. Implement SRI tags for all external scripts you control, and regularly audit what’s actually loading.

Deploy Content Security Policy. Start in report-only mode, analyze the reports, then enforce. CSP won’t catch everything, but it makes entire categories of injection attacks significantly harder to execute.

Educate your users. If you manage a community or internal team, teach them to recognize suspicious behavior—unexpected redirects, performance degradation, unfamiliar domains in the address bar. The r/Seattle mods protected their community by acting on suspicions. Your users can be your first line of detection.

Document your baseline. You can’t detect anomalies without knowing what’s normal. Whether it’s your own production applications or third-party services you rely on, maintain records of expected script sources and content hashes. When something changes, you need to know immediately.

JavaScript injection attacks exploit the fundamental trust model of the web. As defenders, our job is to verify that trust systematically. The techniques we’ve covered—DevTools inspection, content hashing, CSP deployment, and behavioral monitoring—form a layered defense that makes injection attacks visible and often preventable.

The next time you encounter a suspicious page, you won’t just wonder if something’s wrong. You’ll know how to check, what to look for, and how to prove it. That’s the difference between reading about security and practicing it.

Stay in the loop — join 125,000+ IT professionals following Networkyy: Instagram · Facebook · Threads · Medium
🔥 RECOMMENDED FOR YOU

Master JavaScript Security Analysis

Build professional-grade skills in detecting and preventing script injection attacks with hands-on security courses. Learn to audit third-party code, implement CSP policies, and protect your infrastructure from malicious JavaScript.

Start Learning on Coursera →

Retour en haut