Skip to content

Commit 053a226

Browse files
Merge pull request #779 from ossf/add_xss_tests
Add internal tests to xss lab
2 parents 970d331 + 9b5be79 commit 053a226

File tree

1 file changed

+39
-12
lines changed

1 file changed

+39
-12
lines changed

docs/labs/xss.js

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,65 @@ info =
22
{
33
hints: [
44
{
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+
],
710
},
811
{
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+
],
1117
},
1218
{
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+
],
1524
},
1625
{
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+
],
1932
},
2033
{
2134
present: String.raw`\| safe`,
2235
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+
],
2440
},
2541
{
2642
present: String.raw`\|`,
2743
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+
],
2948
},
3049
{
3150
present: String.raw`Markup \(.*\+.*\)`,
3251
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+
],
3456
},
3557
{
3658
absent: String.raw`\+`,
3759
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+
],
3964
},
4065
],
4166
expected: [
@@ -44,6 +69,8 @@ info =
4469
`result = Markup('Original name=') + name`
4570
],
4671
correct: [
72+
// Python PEP 8 recommends no space '=' around keyword use, but
73+
// Python allows it, so we will too.
4774
String.raw`\s* autoescape = select_autoescape \( \) \s*`,
4875
String.raw`\s* < h1 >Hello\x20{{ person }}!< /h1 > \s*`,
4976
String.raw`\s* result = Markup \( ('Original name='|"Original name=") \) \+ name \s*`

0 commit comments

Comments
 (0)