Concepts / Web injection and scripting

Web injection and scripting

Output encoding

Also called output escaping, HTML escaping, contextual encoding

Escaping untrusted data for the exact place it is written, so it is shown as text and never run as code.

Same input: run as code or shown as text
Same input: run as code or shown as text

Written as it is, the browser sees a tag and runs it. Encoded for HTML, the same characters are shown as text.

Output encoding is escaping untrusted data for the exact place it is written, so the browser shows it as text and never runs it. In HTML, < becomes &lt; and a quote &quot;. Each context (HTML body, attribute, URL, <script> block, CSS) has its own rules, so it is done at output, not input. It is the main defence against [[cross-site-scripting|XSS]]. Templates escape by default; bugs come from raw output.

See it on real machines

Read next

Learn it on real machines.

Every lab is a small network of real Linux machines in your browser. Sign in with Google or email to start.

Start this lab