Skip to main content

Sandbox Process Creation


ImportanceReview GuidanceRequires Scanning Tool
HighMerge After Cursory ReviewNo

This codemod sandboxes all instances of and to offer protection against attack.

Left unchecked, and can execute any arbitrary system command. If an attacker can control part of the strings used as program paths or arguments, they could execute arbitrary programs, install malware, and anything else they could do if they had a shell open on the application host.

Our change introduces a sandbox which protects the application:

  import subprocess
+ from security import safe_command
-"echo 'hi'", shell=True)
+, "echo 'hi'", shell=True)
-["ls", "-l"])
+, ["ls", "-l"])

The default safe_command restrictions applied are the following:

  • Prevent command chaining. Many exploits work by injecting command separators and causing the shell to interpret a second, malicious command. The safe_command functions attempt to parse the given command, and throw a SecurityException if multiple commands are present.
  • Prevent arguments targeting sensitive files. There is little reason for custom code to target sensitive system files like /etc/passwd, so the sandbox prevents arguments that point to these files that may be targets for exfiltration.

There are more options for sandboxing if you are interested in locking down system commands even more.

If you have feedback on this codemod, please let us know!


Why is this codemod marked as Merge After Cursory Review?

We believe this change is safe and effective. The behavior of sandboxing and calls will only throw SecurityException if they see behavior involved in malicious code execution, which is extremely unlikely to happen in normal operation.

Codemod Settings