One notice in 5 places (HTML text, attribute, href, script string, style): each place with the escaper picked for it, checked on the built output. An…
Why it matters
XSS is the most commonly met OWASP Top 10 issue, and most bugs are born from assuming there is "one escape function" safe everywhere. But escapeHtml for text is no substitute for scheme checking in an href or escapeJs in a script string. Knowing the output context means knowing why frameworks auto-escape per context, and why raw data in an href/<script>/<style> stays dangerous even when "already escaped".
The key idea
There is no single escape function; escaping must match the output context
Common mistakes
Already applying htmlEncode(), yet href="javascript:…" still runs Safe in text, but href="javascript:…" and onclick still run. Escaping must match the context: HTML, attribute, JS, URL or CSS each has its own rules. For href, check the scheme; allow http(s) or a relative path.
Escaped on save, yet it runs when rendered into a different sink You do not know which context the data ends up in. Store it raw, then escape at render time matching the output context. Escape at output, not at input.
An unquoted attribute breaks from just a space in its value<img alt=DATA> can be broken with just a space. Always quote attributes (alt="…") and use escapeAttr for "'<>.
Try it in this playground
Make HTML text safe with escapeHtml()< and > become entities: the notice shows as text, not a tag.
Close the attribute with escapeAttr() escapeHtml alone does not hold the quote; escapeAttr closes it.
Stop javascript: in href Only scheme checking refuses it; escapeHtml does not touch the scheme.
Make all five places safe at once You switch escaper per place: no single one fits all.