-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement flak8-bandit shell injection rules
This includes rules S602 - S607.
- Loading branch information
Showing
12 changed files
with
549 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from subprocess import Popen, call, check_call, check_output, run | ||
|
||
# Check different Popen wrappers are checked | ||
Popen("true", shell=True) | ||
call("true", shell=True) | ||
check_call("true", shell=True) | ||
check_output("true", shell=True) | ||
run("true", shell=True) | ||
|
||
# Check values that truthy values are treated as true | ||
Popen("true", shell=1) | ||
Popen("true", shell=[1]) | ||
Popen("true", shell={1: 1}) | ||
Popen("true", shell=(1,)) | ||
|
||
# Check command argument looks unsafe | ||
var_string = "true" | ||
Popen(var_string, shell=True) | ||
Popen([var_string], shell=True) | ||
Popen([var_string, ""], shell=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from subprocess import Popen, call, check_call, check_output, run | ||
|
||
# Different Popen wrappers are checked | ||
Popen("true", shell=False) | ||
call("true", shell=False) | ||
check_call("true", shell=False) | ||
check_output("true", shell=False) | ||
run("true", shell=False) | ||
|
||
# Values that falsey values are treated as false | ||
Popen("true", shell=0) | ||
Popen("true", shell=[]) | ||
Popen("true", shell={}) | ||
Popen("true", shell=None) | ||
|
||
# Unknown values are treated as falsey | ||
Popen("true", shell=True if True else False) | ||
|
||
# No value is also caught | ||
Popen("true") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
def foo(shell): | ||
pass | ||
|
||
|
||
foo(shell=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import os | ||
|
||
import commands | ||
import popen2 | ||
|
||
# Check all shell functions | ||
os.system("true") | ||
os.popen("true") | ||
os.popen2("true") | ||
os.popen3("true") | ||
os.popen4("true") | ||
popen2.popen2("true") | ||
popen2.popen3("true") | ||
popen2.popen4("true") | ||
popen2.Popen3("true") | ||
popen2.Popen4("true") | ||
commands.getoutput("true") | ||
commands.getstatusoutput("true") | ||
|
||
|
||
# Check command argument looks unsafe | ||
var_string = "true" | ||
os.system(var_string) | ||
os.system([var_string]) | ||
os.system([var_string, ""]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import os | ||
|
||
# Check all shell functions | ||
os.execl("true") | ||
os.execle("true") | ||
os.execlp("true") | ||
os.execlpe("true") | ||
os.execv("true") | ||
os.execve("true") | ||
os.execvp("true") | ||
os.execvpe("true") | ||
os.spawnl("true") | ||
os.spawnle("true") | ||
os.spawnlp("true") | ||
os.spawnlpe("true") | ||
os.spawnv("true") | ||
os.spawnve("true") | ||
os.spawnvp("true") | ||
os.spawnvpe("true") | ||
os.startfile("true") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import os | ||
|
||
# Check all functions | ||
subprocess.Popen("true") | ||
subprocess.call("true") | ||
subprocess.check_call("true") | ||
subprocess.check_output("true") | ||
subprocess.run("true") | ||
os.system("true") | ||
os.popen("true") | ||
os.popen2("true") | ||
os.popen3("true") | ||
os.popen4("true") | ||
popen2.popen2("true") | ||
popen2.popen3("true") | ||
popen2.popen4("true") | ||
popen2.Popen3("true") | ||
popen2.Popen4("true") | ||
commands.getoutput("true") | ||
commands.getstatusoutput("true") | ||
os.execl("true") | ||
os.execle("true") | ||
os.execlp("true") | ||
os.execlpe("true") | ||
os.execv("true") | ||
os.execve("true") | ||
os.execvp("true") | ||
os.execvpe("true") | ||
os.spawnl("true") | ||
os.spawnle("true") | ||
os.spawnlp("true") | ||
os.spawnlpe("true") | ||
os.spawnv("true") | ||
os.spawnve("true") | ||
os.spawnvp("true") | ||
os.spawnvpe("true") | ||
os.startfile("true") | ||
|
||
# Check it does not fail for full paths | ||
os.system("/bin/ls") | ||
os.system("./bin/ls") | ||
os.system(["/bin/ls"]) | ||
os.system(["/bin/ls", "/tmp"]) | ||
os.system(r"C:\\bin\ls") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.