QamoosTech
SecurityApplication securityIntermediateDjangoPython

Auto-Escaping

PronunciationAW-toh es-KAY-ping

Definition

Auto-escaping is a template feature that automatically converts special characters like < and > in variables into harmless text, so user input can't inject HTML or scripts.

Where you hear it

In Django and Jinja templates, XSS prevention guides, and security reviews of |safe and mark_safe.

Examples

  • Django escapes variables automatically, so a <script> tag shows as plain text.
  • Don't turn auto-escaping off for user content.
  • The comment field shows <b>hi</b> as plain text, because the template escapes it.

Common mistake

Marking user text as safe to "fix" a display problem. That removes the protection and opens an XSS hole.

Don't confuse with

Input validation, which checks data when it comes in. Escaping protects the output when it is shown.

Say it at work

  • In a meeting or chatIs auto-escaping on in this template?
  • In an email or ticketWhy is there a |safe on user input?