Output encoding is a defense that converts untrusted data into a representation the browser treats as text, not executable code. In practice, characters such as <, >, ", and & are escaped before content is placed into HTML, attributes, JavaScript, or URLs. The goal is to preserve the data while removing its ability to change page structure or start script execution.
This matters because many attacks, especially stored XSS, depend on attacker-controlled input being rendered later inside a trusted session. In a feature like avatar uploads, profile names, comments, or file metadata can become dangerous if they are displayed without context-aware encoding. Good defenses use output encoding at the final rendering step, alongside validation and safe templates. Encoding is not a substitute for access control or file-type checks, but it is one of the most important controls for preventing browser-side code execution.


