Skip to content

Commit dfb4e06

Browse files
Lab shell-injection: Move answers to JavaScript
Signed-off-by: David A. Wheeler <[email protected]>
1 parent 0cb2e8e commit dfb4e06

File tree

2 files changed

+20
-34
lines changed

2 files changed

+20
-34
lines changed

docs/labs/shell-injection.html

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,6 @@
1212

1313
<!-- See create_labs.md for how to create your own lab! -->
1414

15-
<!-- Sample expected answer -->
16-
<script id="expected0" type="plain/text">
17-
clean_dir = re.sub(r'[^a-zA-Z0-9]', '', dir_to_list)
18-
</script>
19-
<!--
20-
-->
21-
<script id="expected1" type="plain/text">
22-
subprocess.run(["ls", "-l", clean_dir])
23-
</script>
24-
25-
<!-- Full pattern of correct answer.
26-
In Python, newline and carriage return are whitespace but are *meaningful*
27-
outside of (...). So we match specifically on space (\x20) instead.
28-
This makes our patterns harder to read, unfortunately.
29-
It's conventional to use raw strings in Python for regexes, so we allow
30-
and encourage them, but we'll accept *not* using raw strings since they
31-
don't add value in this situation.
32-
-->
33-
<script id="correct0" type="plain/text">
34-
[\n\r]*\x20\x20clean_dir\x20*=\x20*re\x20*\.\x20*sub\x20*\(
35-
r?('\[\^a-zA-Z0-9\]'|"\[\^a-zA-Z0-9\]") ,
36-
r?(''|"") , dir_to_list \)
37-
\s*
38-
</script>
39-
40-
<script id="correct1" type="plain/text">
41-
[\n\r]*\x20\x20subprocess\x20*\.\x20*run\x20*\(
42-
\[ ('ls'|"ls") , ('-l'|"-l") , clean_dir \]
43-
( , shell = False )?
44-
\)
45-
\s*
46-
</script>
47-
4815
</head>
4916
<body>
5017
<!-- For GitHub Pages formatting: -->

docs/labs/shell-injection.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,5 +241,24 @@ info =
241241
" clean_dir = re . sub( r'[^a-zA-Z0-9]' , '' , dir_to_list )",
242242
" subprocess . run ( [ \"ls\" , \"-l\" , clean_dir ] )"
243243
]
244-
]
244+
],
245+
expected: [
246+
String.raw` clean_dir = re.sub(r'[^a-zA-Z0-9]', '', dir_to_list)`,
247+
String.raw` subprocess.run(["ls", "-l", clean_dir])`
248+
],
249+
// In Python, newline and carriage return are whitespace but are *meaningful*
250+
// outside of (...). So we match specifically on space (\x20) instead.
251+
// This makes our patterns harder to read, unfortunately.
252+
// It's conventional to use raw strings in Python for regexes, so we allow
253+
// and encourage them, but we'll accept *not* using raw strings since they
254+
// don't add value in this situation.
255+
correct: [
256+
String.raw`[\n\r]*\x20\x20clean_dir\x20*=\x20*re\x20*\.\x20*sub\x20*\(
257+
r?('\[\^a-zA-Z0-9\]'|"\[\^a-zA-Z0-9\]") ,
258+
r?(''|"") , dir_to_list \) \s*`,
259+
String.raw`[\n\r]*\x20\x20subprocess\x20*\.\x20*run\x20*\(
260+
\[ ('ls'|"ls") , ('-l'|"-l") , clean_dir \]
261+
( , shell = False )? \) \s*`
262+
],
263+
debug: true,
245264
}

0 commit comments

Comments
 (0)