Why shell=False Does Not Prevent Argument Injection in Subprocess Calls
A developer found that a subprocess call using shell=False and an argument list still produced a bug when a user-supplied value began with a dash, causing grep to treat it as an option. A second failure appeared on Windows under Git Bash, where the MSYS compatibility layer expanded a wildcard in the argument before the program received it. The author explains that both issues originate in arguments rather than the shell, so shell=False addresses command injection but not argument injection. Recommended mitigations include placing -- before user-supplied values, escaping glob characters on Windows, and re-reviewing calls after code changes. The author also released a scanner, sg audit, to detect these patterns in code repositories.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in