Front-End Security Game Day: Defending Against CSP Violations, Third-Party Breaches, and DOM XSS
Overview
This Game Day is a hands-on, gamified workshop designed to train front-end developers, security engineers, and teams on common web vulnerabilities. Participants will attack simulated environments to exploit issues, then defend by implementing fixes. The event simulates real-world scenarios in a safe, isolated setup.
- Duration: 4-6 hours (half-day format, scalable).
- Group Size: 8-24 participants (teams of 2-4 for collaboration).
- Format: Capture-the-Flag (CTF) style with challenges, points, leaderboards, and prizes (e.g., swag or certificates).
- Difficulty: Intermediate (assumes basic HTML/JS knowledge).
- Gamification:
- Points for exploits (red team) and defenses (blue team).
- Leaderboard updates in real-time via a shared dashboard (e.g., Google Sheets or CTFd).
- Bonus rounds for creative solutions.
Learning Objectives
By the end, participants will:
- Understand CSP misconfigurations and evasion techniques.
- Identify and mitigate third-party script supply chain risks.
- Detect and sanitize DOM XSS sinks/sources.
- Apply best practices: CSP headers, script integrity, DOMPurify, etc.
Prerequisites
- Laptop with browser (Chrome/FF DevTools), Node.js, Docker.
- Git clone of provided repo (setup script included).
- Accounts: GitHub, free tier of services like jsDelivr or unpkg.
- Pre-Event Setup (15 mins): Run
docker-compose up for vulnerable apps.
Environment & Tools
- Vulnerable Apps (Dockerized):
- Custom "VulnShop" app (React-based e-commerce sim).
- OWASP Juice Shop (for bonus challenges).
- Attack Tools: Browser DevTools, Burp Suite Community, Postman.
- Defense Tools: CSP Evaluator (csp-evaluator.withgoogle.com), DOMPurify CDN, SRI hash generators.
- Scoring Platform: CTFd (self-hosted Docker) or HackTheBox-style.
- Repo: Hypothetical GitHub: frontend-sec-gameday with Dockerfiles, challenges, hints, and solutions.
Agenda
| Time | Session | Description | Format |
|---|
| 0:00-0:15 | Welcome & Kickoff | Icebreaker, rules, teams, leaderboard intro. Demo a quick CSP bypass. | Lecture + Demo |
| 0:15-1:15 | Lab 1: CSP Violations (100 pts) | Simulate and break CSP. | Hands-on Teams |
| 1:15-1:30 | Break | Coffee/leaderboard check. | - |
| 1:30-2:30 | Lab 2: Third-Party Script Breaches (150 pts) | Hijack supply chains. | Hands-on Teams |
| 2:30-3:30 | Lab 3: DOM XSS Defenses (150 pts) | Exploit and sanitize DOM sinks. | Hands-on Teams |
| 3:30-3:45 | Break | Snacks/leaderboard. | - |
| 3:45-4:15 | Lightning Defenses & Bonus (50 bonus pts) | Quick-fixes competition + open CTF. | Competition |
| 4:15-4:45 | Debrief & Wrap-Up | Share war stories, key takeaways, certs/prizes. | Discussion |
Detailed Labs/Challenges
Lab 1: CSP Violations (Red: Bypass → Blue: Harden)
Scenario: VulnShop loads user-generated "promos" with weak CSP (default-src 'self'; script-src 'unsafe-inline').
Challenges (Progressive, escalating points):
- Bypass Inline Scripts (20 pts): Inject
<script>alert(1)</script> via promo form → Use DevTools to inspect violations.
- Eval/JSONP Evasion (30 pts): Force
eval() on data URLs or JSONP callbacks.
- Nonce/Hash Bypass (50 pts): Given
script-src 'nonce-abc', tamper with nonces via proxy (Burp).
Defenses (Bonus points):
- Implement strict CSP:
script-src 'self' 'nonce-{random}', report-uri.
- Test with CSP Evaluator tool.
- Verify: No alerts on re-injection.
Hints: Check Network tab for policy delivery; use Content-Security-Policy-Report-Only for testing.
Lab 2: Third-Party Script Breaches (Red: Compromise → Blue: Secure)
Scenario: VulnShop pulls analytics from unpkg.com/lodash@compromised (simulated via local mirror with malicious payload).
Challenges:
- SRI Bypass (40 pts): Remove
integrity attr or swap hash → Steal cookies via fetch('/api/user').
- CDN Hijack (50 pts): Use DNS rebinding (local tool provided) to point third-party to attacker server injecting
document.write('<img src=/steal>').
- Subresource Integrity Fail (60 pts): Exploit version pinning fail; tamper with script to exfil data.
Defenses:
- Add SRI hashes (
integrity="sha256-ABC123").
- Use
script-src 'nonce-*' https://trusted-cdn.com.
- Fallback to local copies or module federation.
- Verify: Script blocks on tamper.
Hints: Generate hashes with openssl dgst -sha384 -binary file.js | openssl base64 -A; monitor Console for SRI errors.
Lab 3: DOM XSS Defenses (Red: Sink Hunt → Blue: Sanitize)
Scenario: Search bar with location.hash sink: function search(q) { $('#results').html("Results for " + q); }.
Challenges:
- Basic Sink (30 pts):
?q=<script>alert(1)</script> → Track via sink() mapping.
- Event Handler (50 pts):
q=<img src=x onerror=alert(1)> or q=javascript:alert(1).
- Advanced DOM Clobber (70 pts): Prototype pollution via
history.pushState(decodeURI(hash), ...).
Defenses:
- Use
textContent over innerHTML.
- Integrate DOMPurify:
purify.sanitize(userInput).
- Source tracking: Whitelist safe APIs (e.g.,
URL.createObjectURL).
- Verify: No execution on payloads from XSS Hunter list.
Hints: Use Chrome's Sources tab with breakpoints on DOM props; test payloads from PayloadsAllTheThings.
Facilitator Notes
- Roles: 1-2 facilitators per 12 participants (monitor Slack/Discord for hints).
- Hints System: Tiered (free after 5 mins, detailed after 10).
- Safety: All in iframes/localhost; no real exfil.
- Metrics: Pre/post quiz (e.g., Google Forms) for ROI.
- Extensions: Add clickjacking (X-Frame-Options), HSTS preload sim.
Resources
- Slides: Google Slides deck with visuals/animations.
- Cheat Sheet: One-pager on CSP directives, OWASP XSS Prevention.
- Further Reading: OWASP CSP Cheat Sheet, DOM XSS paper by Gareth Heyes.
- Post-Event: Recorded session, GitHub solutions (locked until end).
This plan is turnkey—fork the repo, run Docker, and go! Expected ROI: Teams ship CSP-hardened apps next sprint. Questions? Ping the facilitator. 🚀