Skip to content

Commit 18d2846

Browse files
docs(xss): clarify attribute-context examples and fix contradiction (mdn#40786)
* docs(xss): clarify attribute-context examples and fix contradiction * Update files/en-us/web/security/attacks/xss/index.md --------- Co-authored-by: Hamish Willee <hamishwillee@gmail.com>
1 parent a353161 commit 18d2846

File tree

1 file changed

+3
-2
lines changed
  • files/en-us/web/security/attacks/xss

1 file changed

+3
-2
lines changed

files/en-us/web/security/attacks/xss/index.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ However, suppose the template is like this:
203203
<div \{{ my_input }}></div>
204204
```
205205

206-
In this context the browser will treat the `my_input` variable as an HTML attribute. If `my_input` is `onmouseover="alert('XSS')"`, the output encoding provided by Django won't prevent the attack.
206+
In this context the browser will treat the `my_input` variable as an HTML attribute. Because Django encodes quotes (`"``&quot;`, `'``&#x27;`), the payload `onmouseover="alert('XSS')"` will not execute.
207+
However, an unquoted payload like `onmouseover=alert(1)` (or using backticks, ``onmouseover=alert(`XSS`)``) will still execute, because attribute values need not be quoted and backticks are not escaped by default.
207208

208209
The browser uses different rules to process different parts of a web page — HTML elements and their content, HTML attributes, inline styles, inline scripts. The type of encoding that needs to be done is different depending on the context in which the input is being interpolated.
209210

@@ -218,7 +219,7 @@ What's safe in one context may be unsafe in another, and it's necessary to under
218219
<div class=\{{ my_class }}>...</div>
219220
```
220221

221-
An attacker can exploit this to inject an event handler attribute, by using input like `some_id onmouseover="alert('XSS!')"`. To prevent the attack, quote the placeholder:
222+
An attacker can exploit this to inject an event handler attribute, by using input like `some_id onmouseover=alert(1)`. To prevent the attack, quote the placeholder:
222223

223224
```django example-good
224225
<div class="\{{ my_class }}">...</div>

0 commit comments

Comments
 (0)