Guided exercise
Browser Security Basics
Each step brings together the instructions, examples and evidence you need. Move freely using Next, Previous or the step list.
Before you start
The lesson at a glance
Use a supplied local message board to see how a browser displays messages. First post ordinary text, then watch a harmless demo change a marker. Follow a guided code repair so messages stay text, and check the result.
Time: approximately 75–90 minutes.
Prerequisites: opening files in a desktop browser and saving a file in a plain-text code editor. The worksheet introduces the HTML and JavaScript needed for the guided repair. No terminal, Node, npm, server, internet connection, or CVE Lite installation is required for students.
What the exercise looks like
Original lesson screenshots. You’ll revisit these beside the relevant instructions.
Safety and scope
Use this supplied app on your own computer for the lesson. Do not publish the intentionally unsafe starter or connect it to a real service.
Use Insert harmless demo only in this lab. It changes the visible demo marker. Do not paste it into other websites or browser consoles.
Use made-up messages, not passwords or personal information. Messages stay in this tab's memory. Author and reader are two views, not real accounts. Reload and Reset board remove messages you added and restore the two example messages.
No browser security setting needs to change. If the page does not work, ask your instructor for help.
What you will learn and verify
- Post and read messages using the supplied controls.
- Observe the harmless demo's marker change.
- Explain the difference between displaying text and interpreting HTML.
- Complete a guided repair using
textContent. - Repeat the demo and checks, and report actual results.
No backend knowledge or reading of data.js or app.js is required. More experienced JavaScript students may choose the worksheet's independent repair challenge. It is optional and not needed for full credit.
Worksheet: browser security basics
You will use a supplied message board, watch a harmless demonstration, and repair how messages appear. Allow about 75–90 minutes, including discussion. You need a desktop browser and a plain-text code editor. You do not need a terminal or previous knowledge of browser programming.
Choose the row matching your folder. Keep the same copy open throughout the lesson.
| Your folder | Open in your browser | Open in your code editor |
|---|---|---|
Student-only kit (contains app/) | app/index.html | app/render.js |
Full repository, inside this exercise (contains student/) | student/index.html | student/render.js |
Extract a downloaded ZIP first. Read Safety. Open the submission template to record observations. You only edit render.js; you do not need to read data.js, app.js, or the check code.
In the wild: real-world case study
The Samy MySpace worm (2005, stored and DOM XSS)
- Incident & Year: Samy MySpace Worm (2005)
- Vulnerability: No CVE assigned (MySpace Application Stored XSS) · CWE-79 (Improper Neutralization of Input During Web Page Generation - Cross-Site Scripting) · OWASP A05:2025 Injection
- Root Cause: MySpace inserted user profile inputs directly into the page markup without treating them strictly as text. By obfuscating JavaScript within browser-interpreted CSS expressions, the payload bypassed tag blacklists and executed automatically whenever another user viewed the profile, forcing the visitor's browser to add the author as a friend and copy the payload into their own profile.
- Real-World Impact: Over 1 million user profiles were infected within 20 hours, taking down MySpace to cleanse profiles in what remains one of the fastest-spreading web worms in internet history.
- Remediation Tie-In: Exercise 04 teaches the core defensive control: treating untrusted user inputs strictly as text using safe browser APIs (
textContent,replaceChildren,document.createTextNode) instead of inserting strings intoinnerHTML, preventing browser rendering engines from parsing user data as executable markup. - References: Samy Kamkar Technical Explanation · OWASP XSS Prevention Cheat Sheet
The British Airways Magecart client-side injection (2018)
- Incident & Year: British Airways (2018)
- Vulnerability: CWE-79 (Improper Neutralization of Input) · CWE-829 (Inclusion of Functionality from Untrusted Control Sphere) · OWASP A05:2025 Injection
- Root Cause: Adversaries compromised server credentials and altered a third-party script loaded on British Airways' payment pages. The modified script executed inside passengers' browsers, hooking form submit events to exfiltrate payment card numbers and CVV codes in real time.
- Real-World Impact: Approximately 380,000 payment transactions were intercepted, resulting in a landmark £20 million GDPR penalty from the UK Information Commissioner's Office (ICO).
- Remediation Tie-In: While safe DOM APIs like
textContentprotect internal application sinks from markup injection, defense against third-party script tampering relies on controls such as Subresource Integrity (SRI) to detect and block scripts whose content differs from expected hashes, protecting against unexpected script modifications. - References: UK ICO Penalty Notice (British Airways) · CISA Alert on Magecart
Troubleshooting
If HTML source appears, open index.html in the browser rather than the editor. If buttons do nothing, extract all files and keep them together. After a repair, check that the complete scaffold was copied, the blank was filled, and the file is named render.js, not render.js.txt. Save and reload the matching browser copy. Ask the instructor for help with any remaining error; never disable browser security.
Lesson references
Return to examples, teaching notes or the worked solution when you need them.
Optional extension: vocabulary for later lessons (not graded)
The unsafe behavior is an example of cross-site scripting (XSS): message content becomes JavaScript instructions in the browser. A trust boundary is a point where outside data is handled by program code; here it is where message strings become displayed elements. OWASP Top 10:2025 groups injection risks, including XSS, under A05 Injection. This lesson covers one example, not that whole category.
A server is a program that answers other programs' requests; a database stores data for later use. This lab uses neither: messages stay in this tab's memory. Stored XSS in a shared application could involve saving a harmful message and displaying it to another person later. This local demo does not show that delivery or a database break-in. A future server lesson can address account permissions, input checks, and safe database queries separately.
CVE Lite checks third-party dependencies for known vulnerabilities. This flaw is in the board's own display code, so dependency scanning does not repair it. The six checks support this plain-text repair; they do not prove every part of an application is secure. Discuss these distinctions only if time and prior experience permit.
Screenshot sources and context
Exercise screenshots
These examples show what to look for. Use your own run as submission evidence.
Starting point

Unsafe starter reader view after the demo message, with failing security checks.
Expected result

Repaired reader view treats message markup as text and passes all six checks.
Source
Captured from the supplied student and solution apps using tooling/browser-smoke.cjs. The images show the local demo and check results, not solution code.
Worked solution — compare after your attempt
Worked reference: attempt the worksheet first, then compare your reasoning and results.
Worked solution: browser security basics
Open index.html in this directory for the standalone corrected app. No server or package installation is required. All app files match the starter except render.js.
The renderer creates a list item for each message and uses textContent to put the complete message inside it. Unlike innerHTML, this displays the characters as text rather than interpreting them as HTML instructions. It preserves punctuation and message order. replaceChildren() removes the previous displayed items before drawing them again.
This is the completed version of the worksheet's guided scaffold. Both the guided route and an equivalent independent repair can earn full credit.
Verify
- Click Author view, enter an ordinary message, click Post message, then Reader view. It should appear after the examples.
- Repeat with
<strong>Hello</strong>. The tags should be visible as text. - Click Reset board. Confirm the marker is
UNCHANGED. - Click Author view → Insert harmless demo → Post message → Reader view. The full demo text should appear; the marker should remain
UNCHANGED. - Click Run browser checks. Expect 6 of 6 PASS, compared with 3 of 6 PASS in the starter.
- Repeat punctuation, spaces-only input, and multiple messages in posting order. Click Reset board → Reader view and confirm the two example messages return.
Reloading also removes added messages and restores the two examples. Browser checks use a temporary area and restore the marker to its previous value.
See the instructor walkthrough and rubric. The required explanation is simply why message instructions ran before repair and stay text afterward. Backend and OWASP discussion is optional.
This repair fits a plain-text message board. Other uses, such as allowing rich HTML formatting, need separate design and verification.
Teaching package
- Worksheet and submission template.
- Teaching plan, walkthrough, and 100-point rubric.
- Worked solution, with a standalone corrected app.
From the repository root, instructors with Node can export a student-only kit:
node tooling/package-student-kit.mjs 04-browser-security-basics browser ./dist/browser-security
The destination must not exist. Distribute the generated folder when withholding instructor materials and the worked solution. It includes the intentionally guided scaffold and hints. Students do not need Node. The full solution remains publicly accessible in this repository; the export is not an examination-security mechanism.
Optional context for instructors
This is one cross-site scripting (XSS) example within OWASP Top 10:2025 A05 Injection, not complete coverage of that category. These public category references do not imply institutional endorsement.
CVE Lite scans dependencies for known vulnerabilities; it does not detect this intentional flaw in the app's own code. Students do not need to run a scanner here.
Author and reader are views in one local tab, with messages held in memory. There are no accounts, server, database, or real cross-user delivery. The board requires plain text, which is why textContent fits this repair. Backend controls and other output contexts belong to later lessons. The worksheet's technical extension is optional and ungraded.
In the wild: real-world case study
The Samy MySpace worm (2005, stored and DOM XSS)
- Incident & Year: Samy MySpace Worm (2005)
- Vulnerability: No CVE assigned (MySpace Application Stored XSS) · CWE-79 (Improper Neutralization of Input During Web Page Generation - Cross-Site Scripting) · OWASP A05:2025 Injection
- Root Cause: MySpace inserted user profile inputs directly into the page markup without treating them strictly as text. By obfuscating JavaScript within browser-interpreted CSS expressions, the payload bypassed tag blacklists and executed automatically whenever another user viewed the profile, forcing the visitor's browser to add the author as a friend and copy the payload into their own profile.
- Real-World Impact: Over 1 million user profiles were infected within 20 hours, taking down MySpace to cleanse profiles in what remains one of the fastest-spreading web worms in internet history.
- Remediation Tie-In: Exercise 04 teaches the core defensive control: treating untrusted user inputs strictly as text using safe browser APIs (
textContent,replaceChildren,document.createTextNode) instead of inserting strings intoinnerHTML, preventing browser rendering engines from parsing user data as executable markup. - References: Samy Kamkar Technical Explanation · OWASP XSS Prevention Cheat Sheet
The British Airways Magecart client-side injection (2018)
- Incident & Year: British Airways (2018)
- Vulnerability: CWE-79 (Improper Neutralization of Input) · CWE-829 (Inclusion of Functionality from Untrusted Control Sphere) · OWASP A05:2025 Injection
- Root Cause: Adversaries compromised server credentials and altered a third-party script loaded on British Airways' payment pages. The modified script executed inside passengers' browsers, hooking form submit events to exfiltrate payment card numbers and CVV codes in real time.
- Real-World Impact: Approximately 380,000 payment transactions were intercepted, resulting in a landmark £20 million GDPR penalty from the UK Information Commissioner's Office (ICO).
- Remediation Tie-In: While safe DOM APIs like
textContentprotect internal application sinks from markup injection, defense against third-party script tampering relies on controls such as Subresource Integrity (SRI) to detect and block scripts whose content differs from expected hashes, protecting against unexpected script modifications. - References: UK ICO Penalty Notice (British Airways) · CISA Alert on Magecart

