☼
⌃
☰

Cross-Site Scripting

Table of Contents

Malicious JavaScript injected into a page executes in the victim's browser under the target origin. The attacker inherits the victim's session, can read the DOM, exfiltrate cookies, make authenticated requests, and redirect users. Severity depends on type and context — Stored XSS is highest impact, DOM-based the hardest to detect.

Related: CSRF HTTP Security Headers Session Management Testing Web Application Testing Methodology PT1 Vulnerability Classification Cheat Sheet

1. XSS Types

Type How it works Persistence Impact
Reflected Input echoed back in response None — victim must click link Medium
Stored Payload stored in DB, rendered for all users Persistent High
DOM-based JS reads attacker-controlled source and writes to sink Varies Medium–High

2. Finding XSS

Injection Points

TEXT
Test every input that appears in the response:
- URL parameters: ?q=, ?name=, ?search=
- Form fields: login, search, comment, profile fields
- HTTP headers reflected in response: User-Agent, Referer, X-Forwarded-For
- JSON/API response values rendered in the page
- URL path segments: /user/<name>/profile

Initial Probe

Start with a benign string that is visually distinct — confirm it appears in the response before injecting payloads:

SHELL
# Probe string — check where it appears in the response
xsstest1234

# Then check the page source to identify the context:
# - Between HTML tags: <p>xsstest1234</p>
# - In an attribute: <input value="xsstest1234">
# - In a script block: var x = "xsstest1234";
# - In a URL: href="xsstest1234"

The context determines which payload to use.

3. Payloads by Context

HTML Body Context

HTML \n\n\n\n\n