Concept
What Is an XSS Context?
In XSS, context means where exactly the user's input is placed in the webpage.
This matters because the same input can be safe in one location but dangerous in another.
Common XSS contexts
User input can appear inside:
HTML text: <p>USER_INPUT</p>
HTML attributes: <input value="USER_INPUT">
JavaScript: <script>
let name = 'USER_INPUT';
</script>
URLs: <a href="USER_INPUT">
Each context has different rules for safely handling untrusted data. XSS protection depends on the context where the data is inserted.
You need to know where the data will be used and apply the appropriate context-specific output encoding.