Output encoding
Converting data into a safe form for the exact place it is written, such as HTML text, an attribute, JavaScript or a URL, so a browser or other interpreter treats it as data and not as code.
Output encoding, also called output escaping, converts data into a form the receiving interpreter reads as plain data, at the point where the application writes it out. In a web page, characters such as angle brackets and quote marks are replaced with harmless equivalents, so text that contains script is displayed rather than run. NIST SP 800-53 Rev. 5 names output escaping (output encoding) beside parameterised interfaces as a way of preventing injection (SI-10(6)), and NIST SP 800-218 includes encoding all outputs among its secure coding examples.
Encoding has to match the context. OWASP’s Cross Site Scripting Prevention Cheat Sheet treats HTML content, HTML attributes, JavaScript, CSS and URLs as separate contexts, and using the wrong method can leave the weakness open. So encoding happens on output, where the context is known, not once on input. It is the principal defence against cross-site scripting, commonly combined with framework auto-escaping, HTML sanitisation for formatted user text, and a Content Security Policy. It complements input validation, which checks data on the way in, and does the same job for pages that parameterised queries do for database commands.
Exam relevance: a scenario in which user-supplied text runs as script in other visitors’ browsers is likely to point to missing output encoding. Candidates are expected to choose context-aware encoding over input filtering alone.