|
2 | 2 | { |
3 | 3 | hints: [ |
4 | 4 | { |
5 | | - absent: "autoescape", |
6 | | - text: "Add an `autoescape=` parameter." |
| 5 | + present: "(Autoescape|AUTOESCAPE)", |
| 6 | + text: "The name `autoescape` must be in all lowercase.", |
| 7 | + examples: [ |
| 8 | + [ "Autoescape" ], |
| 9 | + ], |
7 | 10 | }, |
8 | 11 | { |
9 | | - present: String.raw`autoescape [^:\x20]`, |
10 | | - text: "The name `autoescape` needs to be followed by `=`." |
| 12 | + present: "([Aa]uto_[Ee]scape|AUTO_ESCAPE)", |
| 13 | + text: "Use `autoescape` in all lowercase with no underscores.", |
| 14 | + examples: [ |
| 15 | + [ "auto_escape" ], |
| 16 | + ], |
11 | 17 | }, |
12 | 18 | { |
13 | | - present: "(Autoescape|AUTOESCAPE)", |
14 | | - text: "The name `autoescape` must be in all lowercase." |
| 19 | + absent: "autoescape", |
| 20 | + text: "Add an `autoescape=` parameter.", |
| 21 | + examples: [ |
| 22 | + [ "" ], |
| 23 | + ], |
15 | 24 | }, |
16 | 25 | { |
17 | | - present: "([Aa]uto_[Ee]scape|AUTO_ESCAPE)", |
18 | | - text: "Use `autoescape` in all lowercase with no underscores." |
| 26 | + present: 'autoescape', |
| 27 | + absent: String.raw`autoescape\x20*=`, |
| 28 | + text: "The name `autoescape` needs to be followed by `=`.", |
| 29 | + examples: [ |
| 30 | + [ "autoescape" ], |
| 31 | + ], |
19 | 32 | }, |
20 | 33 | { |
21 | 34 | present: String.raw`\| safe`, |
22 | 35 | index: 1, |
23 | | - text: "The text `| safe` indicates that this text is trusted and should not be escaped further. However, in context this data could be provided from an attacker and is NOT safe. Remove the marking." |
| 36 | + text: "The text `| safe` indicates that this text is trusted and should not be escaped further. However, in context this data could be provided from an attacker and is NOT safe. Remove the marking.", |
| 37 | + examples: [ |
| 38 | + [ null, " <h1>Hello {{ person | safe }}!</h1>" ], |
| 39 | + ], |
24 | 40 | }, |
25 | 41 | { |
26 | 42 | present: String.raw`\|`, |
27 | 43 | index: 1, |
28 | | - text: "The `|` is used to separate the computed value from the safe marking, but we will not use that marking. Remove the vertical bar." |
| 44 | + text: "The `|` is used to separate the computed value from the safe marking, but we will not use that marking. Remove the vertical bar.", |
| 45 | + examples: [ |
| 46 | + [ null, " <h1>Hello {{ person | }}!</h1>" ], |
| 47 | + ], |
29 | 48 | }, |
30 | 49 | { |
31 | 50 | present: String.raw`Markup \(.*\+.*\)`, |
32 | 51 | index: 2, |
33 | | - text: "Having a concatenation (+) *inside* the call to Markup is a vulnerability. The call to Markup presumes we are passing text that is *not* supposed be escaped. If it is supposed to be escaped, it should be concatenated outside the initial construction of the Markup object." |
| 52 | + text: "Having a concatenation (+) *inside* the call to Markup is a vulnerability. The call to Markup presumes we are passing text that is *not* supposed be escaped. If it is supposed to be escaped, it should be concatenated outside the initial construction of the Markup object.", |
| 53 | + examples: [ |
| 54 | + [ null, null, " result = Markup('Original name=' + name)" ], |
| 55 | + ], |
34 | 56 | }, |
35 | 57 | { |
36 | 58 | absent: String.raw`\+`, |
37 | 59 | index: 2, |
38 | | - text: "Our expected answer includes concatentation using `+`. We expect something like `Markup('Original name='` followed by `+` followed by the variable containing the data that needs to be escaped." |
| 60 | + text: "Our expected answer includes concatentation using `+`. We expect something like `Markup('Original name='` followed by `+` followed by the variable containing the data that needs to be escaped.", |
| 61 | + examples: [ |
| 62 | + [ null, null, ' result = Markup(f"Original name={name}' ], |
| 63 | + ], |
39 | 64 | }, |
40 | 65 | ], |
41 | 66 | expected: [ |
|
44 | 69 | `result = Markup('Original name=') + name` |
45 | 70 | ], |
46 | 71 | correct: [ |
| 72 | + // Python PEP 8 recommends no space '=' around keyword use, but |
| 73 | + // Python allows it, so we will too. |
47 | 74 | String.raw`\s* autoescape = select_autoescape \( \) \s*`, |
48 | 75 | String.raw`\s* < h1 >Hello\x20{{ person }}!< /h1 > \s*`, |
49 | 76 | String.raw`\s* result = Markup \( ('Original name='|"Original name=") \) \+ name \s*` |
|
0 commit comments