Skip to main content
Guide4 min read

When Your Site Got Pwned (And CSP Could've Stopped It)

By The bee2.io Engineering Team at bee2.io LLC

A real incident timeline showing how Content Security Policy prevents XSS attacks. What went wrong, how they fixed it, and why your site needs CSP now.
A real incident timeline showing how Content Security Policy prevents XSS attacks. What went wrong, how they fixed it, and why your site needs CSP now.

Picture this: it's 3 AM on a Tuesday, and your on-call engineer is frantically refreshing the analytics dashboard because users are reporting that clicking "checkout" is now redirecting them to a cryptocurrency casino. Congratulations, your website has been compromised by an XSS attack. And somewhere, a security person who recommended Content Security Policy six months ago is not saying "I told you so" out of pure professionalism.

Let's walk through what actually happened at a mid-sized e-commerce platform last year, because nothing teaches you CSP's value quite like watching it fail to exist in production.

The Timeline: How 47 Minutes of Chaos Unfolded

3:14 AM - Detection: A customer tweets that their payment got "weird." Then another. Then seventeen more. Your Slack floods with notifications like an angry beehive someone poked with a stick. Someone runs a quick browser inspection and finds a script tag pointing to an external domain that definitely wasn't in your codebase. XSS attack confirmed. Your site is basically walking around with its fly open and nobody has the heart to tell you- except they're all tweeting about it.

3:22 AM - Triage: The engineering lead discovers the culprit: a third-party analytics library they integrated last month had a vulnerability that let attackers inject malicious scripts. The library itself was legitimate. The attack vector was legitimate. The problem? There was absolutely nothing preventing random scripts from executing on your domain.

3:31 AM - Impact Assessment: You're looking at roughly 12,000 active sessions affected before they deployed the kill switch. Your incident report later shows that without any Content Security Policy in place, the attacker had free reign to steal session tokens, redirect users, and install keyloggers. In industry data, organizations without CSP experience 3x more successful XSS attacks than those with proper policies in place.

3:47 AM - Root Cause: The postmortem reveals the obvious culprit: your CSP was effectively nonexistent. You had no explicit whitelisting of script sources. You weren't validating third-party dependencies. You were running with script-src 'unsafe-inline' somewhere in your codebase, which is the security equivalent of "CSP: just kidding."

The Fix That Should've Happened Three Months Earlier

Here's where it gets interesting. By 5 AM, the team had deployed a real Content Security Policy with specific directives. Let's break what actually worked:

  • script-src 'self' trusted-cdn.example.com - Only scripts from your own domain or explicitly whitelisted CDNs can execute. Revolutionary concept: you get to decide what code runs on your site.
  • default-src 'self' - Everything else defaults to same-origin only, because"trust everything" is not a security posture, it's a cry for help.
  • report-uri /csp-violations - Every time something tries to break the policy, it phones home. You get visibility instead of surprise attacks.
  • frame-ancestors 'none' - No clickjacking through iframes, because apparently that's still a thing in 2026.

The really embarrassing part? They could've tested this months ago. CSP deployments don't require you to yeet it into production and hope. You can run report-only mode first, which means "monitor violations but don't actually block them." It's the training wheels of security policies. That analytics library would've triggered CSP violations immediately in report-only mode, giving them weeks of warning instead of minutes of panic.

What They Should've Done (And What You Should Do Right Now)

The postmortem wasn't really about the attack- attacks happen. It was about the total absence of a basic security control. One major retailer we know about had implemented CSP three years prior and their version of this incident lasted 8 minutes instead of 47, because their policy blocked the malicious script before it executed.

The deployment strategy that actually works looks like this: Start with report-only mode for two weeks. Monitor for legitimate violations in your csp-violations endpoint. Tighten the policy. Then move to enforcement mode. Done. You've now got a bodyguard for your site that actually knows which guests to let in.

Go audit your site right now. Check your HTTP headers for Content-Security-Policy. If you don't see it, or if you see 'unsafe-inline' anywhere in there, you're living in 2015 and the attack surface is wider than a pickup truck convention.

Disclaimer: This article is for informational purposes only and does not constitute legal, professional, or compliance advice. SCOUTb2 is an automated scanning tool that helps identify common issues but does not guarantee full compliance with any standard or regulation.

securityCSPXSSContent-Security-Policy

Stop finding issues manually

SCOUTb2 scans your entire site for accessibility, performance, and SEO problems automatically.