Overview
Demonstrates how unsanitized output of user input can lead to cross‐site scripting attacks.
Vulnerable Code
// vuln_xss.php
if (isset($_GET['input'])) {
echo "User input: " . $_GET['input'];
}
Exploit Demo

Example URL: ?input=<script>alert('XSS')</script>
Secure Code
// sec_xss.php
echo htmlspecialchars($_GET['input'], ENT_QUOTES, 'UTF-8');
Remediation & Lessons
- Always escape user‐supplied data before outputting to HTML.
htmlspecialchars()
withENT_QUOTES
covers both single and double quotes.- Consider a CSP header to further mitigate XSS risks.