🔐Output Encoding
Also known as HTML Escaping, Output Escaping, HTML Encoding
Turning signs like < into safe codes. Then user text can go on a page.
Think of it like
Think of it like putting a toy sword in a glass case. People can see it, but nobody can swing it.
Example
Emma types <b>hi</b> as her name. The page encodes it, so other users see the tags as plain text, not bold words.
Why it matters
It turns an attacker's script into harmless words. Most modern frameworks do it for you by default.
Definition
Example code
html
<!-- What the user typed -->
<script>alert(1)</script>
<!-- What the page writes -->
<script>alert(1)</script>Common mistake
Key takeaways
- 1Encode on the way out. Just before text reaches the page.
- 2Match the place. HTML, links and scripts differ.
- 3Trust the framework. Keep its safe default on.