June 28, 2026
Understanding Reflected XSS: A Walkthrough of HTML Context Injection
Cross-Site Scripting (XSS) is one of the most common and impactful web vulnerabilities. In this write-up, I will demonstrate how to exploit…
By Albert Simanjuntak
1 min read
Cross-Site Scripting (XSS) is one of the most common and impactful web vulnerabilities. In this write-up, I will demonstrate how to exploit a Reflected XSS vulnerability where the application fails to properly encode user input, allowing for arbitrary JavaScript execution.
Vulnerability Analysis
The target application features a search function that is vulnerable to Reflected Cross-Site Scripting (XSS). The objective of this lab is to execute the alert() function in the browser by injecting malicious JavaScript. The vulnerability exists because the application reflects user-supplied input directly into the HTML response without any form of sanitization or output encoding. Consequently, the browser interprets the input as executable code rather than plain text.
Exploitation Steps
To solve this lab, I performed the following steps to inject and execute the script:
- Locate the Injection Point: I identified the search functionality on the application's homepage, which serves as the entry point for the reflected input.
- Inject the Payload: I entered the following script into the search box:
<script>alert(1)</script>.
- Execution: Upon submitting the search, the browser rendered the injected
<script>tag and executed thealert(1)function, confirming the presence of the vulnerability and solving the lab.
Conclusion
This lab demonstrates the critical risk of reflecting user-provided data directly into an HTML context without proper security controls.
- Key Lesson: The primary defense against XSS is the implementation of context-aware output encoding. By converting special characters (such as < and >) into their corresponding HTML entities, the browser will treat the input as text, effectively neutralizing the malicious script.
- Final Thoughts: Understanding how browsers interpret HTML and JavaScript is essential for identifying XSS vulnerabilities and building more secure web applications.