CYBERSECURITY TRAINING

Local XSS Demonstration Lab

Intentionally vulnerable application for controlled security education.

SECURE MODE
โœ“ SECURE MODE User-controlled output is encoded with htmlspecialchars() before being inserted into HTML.
01

Stored XSS Demonstration

Submit a comment and observe how it is rendered.

SAFE OUTPUT โ€” STORED XSS MITIGATION

Harmless test payloads

For example:

<script>alert('Local XSS demo')</script>

Or a non-popup demonstration:

<script>document.body.dataset.xssDemo='executed';</script>

These examples only demonstrate JavaScript execution in this local page.

02

Reflected XSS Demonstration

Data is supplied through the URL and immediately reflected.

SAFE OUTPUT โ€” REFLECTED XSS MITIGATION
Server response:
Nothing reflected yet.

Example

<script>alert('Reflected XSS')</script>

In Vulnerable Mode, the server places this user-controlled value directly into the HTML response.

03

Comment History

Comments are persisted in MySQL and rendered below.

No comments have been submitted yet.

What happened?

Secure Mode still receives the same user-controlled input, but it encodes special HTML characters before displaying it.

For example, characters such as < and > are represented as HTML entities rather than being interpreted as HTML markup.

Consequently, the browser displays the payload as text instead of treating it as executable HTML.

How to fix it

Treat all user-controlled data as untrusted when it crosses into an HTML context.

htmlspecialchars( $value, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8' );

Output encoding is context-dependent. This example protects values being placed into normal HTML text or attribute contexts. Other contexts, such as JavaScript, CSS, URLs, or SQL, require their own appropriate handling.

The database layer also uses PDO prepared statements so the demonstration does not unnecessarily introduce SQL injection.

Safe demonstration behavior