

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Cross-Site Scripting (XSS)
incomplete
2: Fix Cross-Site Scripting
incomplete
3: Cross-Site Request Forgery (CSRF)
incomplete
4: CSRF Tokens
incomplete
5: Content Security Policy
incomplete
6: Legitimate Inline Scripts
incomplete
7: Sandboxing 'iframe' Elements
incomplete
8: Clickjacking
incomplete
9: Same-Origin and Referrer Policies
incomplete
10: Cross-Origin Resource Sharing
incomplete
11: Route-Scoped CORS
incomplete
12: Security Header Middleware
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Go's html/template package performs contextual escaping. It tracks where a value appears and encodes an ordinary string for that context:
<p>{{.ReviewBody}}</p>
<a href="{{.ProfileURL}}">Profile</a>
<script>
const displayName = {{.DisplayName}};
</script>
In HTML text, < becomes < instead of starting a tag. In a URL attribute, an unsafe scheme such as javascript: is filtered. In JavaScript, a string becomes a quoted JavaScript value rather than source code.
Contextual escaping works only while values remain ordinary Go types. Types such as template.HTML, template.URL, and template.JS tell the engine to trust content that would otherwise be escaped.
Never convert untrusted input to a trusted template type. Those types are escape hatches for content your application already knows is safe.
Client-side code needs the same discipline. Prefer textContent when inserting text into the DOM. Use innerHTML only when the feature truly needs HTML and the value has been processed by a maintained HTML sanitizer.