Course contentsShow
← Security
Lesson 630 of 3,05214. Web Security - XSS and Content InjectionFree lesson

Reflected XSS: Immediate Execution

Learning how reflected XSS works when malicious scripts are immediately returned in HTTP responses.

Reflected XSS: Immediate Execution

What you'll learn: How reflected XSS exploits work when malicious scripts are immediately executed through HTTP responses.


The Core Idea

Reflected XSS (Cross-Site Scripting) happens when an attacker injects malicious JavaScript into a web request, and the server immediately reflects that script back in its HTTP response—without storing it. The victim's browser then executes the script instantly when the page loads.

Think of it like a twisted echo chamber: you shout malicious code at a wall (the server), and it bounces straight back—but now your browser thinks it's legitimate page content and runs it.

How It Works

  1. Attacker crafts a malicious URL containing JavaScript in a parameter (like a search query)
  2. Victim clicks the link (often via phishing or social engineering)
  3. Server processes the request and includes the unsanitized input directly in the HTML response
  4. Browser receives the response and immediately executes the embedded script
  5. Attack succeeds in the same HTTP request-response cycle—no database or storage involved

Why "Immediate" Matters

Unlike stored XSS (which saves the payload for later), reflected XSS executes right away during the current HTTP interaction. The malicious script lives only in the URL and the immediate response. Once the page is gone, so is the attack—unless the victim clicks the malicious link again.

This immediacy means the attacker must trick users into clicking specially crafted links, making social engineering a critical component of reflected XSS attacks.

Common Attack Vector

Search boxes and error messages are prime targets because they often echo user input back immediately: "Your search for [malicious script here] returned no results."

Key Takeaway: Reflected XSS executes malicious scripts immediately within the HTTP response, requiring the attacker to deliver the payload through a crafted URL that victims must visit.