Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b3W3uHbHAmM3orhn7b
26 lines
959 B
Plaintext
26 lines
959 B
Plaintext
== 1. VULNERABLE: build a shell string from user input
|
|
$ sh -c wc -c report.txt; cat secret.txt
|
|
18 report.txt
|
|
TOP-SECRET [exit 0]
|
|
|
|
== 2. SAFE: argument list, no shell. The whole input is one filename
|
|
$ wc -c report.txt; cat secret.txt
|
|
wc: 'report.txt; cat secret.txt': No such file or directory [exit 1]
|
|
|
|
== 3. SAFE but still a trap: option injection. Input '-l' is read as a flag
|
|
$ ls -l
|
|
total 8
|
|
-rw-r--r-- 1 root root 18 Nov 26 00:48 report.txt
|
|
-rw-r--r-- 1 root root 11 Nov 26 00:48 secret.txt [exit 0]
|
|
(the caller wanted to list a file called '-l'; ls took it as an option)
|
|
|
|
== 4. FIX: '--' ends option parsing, then validate
|
|
$ ls -- -l
|
|
ls: cannot access '-l': No such file or directory [exit 2]
|
|
|
|
== 5. FIX: allow-list the input before it gets anywhere near a command
|
|
'report.txt' -> true
|
|
'report.txt; cat secret.txt' -> false
|
|
'-l' -> false
|
|
'../etc/passwd' -> false
|