-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement flak8-bandit shell injection rules #3924
Merged
charliermarsh
merged 9 commits into
astral-sh:main
from
robyoung:implement-bandit-shell-injection-rules
Apr 13, 2023
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e6443de
Implement flak8-bandit shell injection rules
robyoung 8954586
Add spawnve to _typos.toml
robyoung 68ddf14
Update crates/ruff/src/rules/flake8_bandit/rules/shell_injection.rs
robyoung 1ede01e
Update crates/ruff/src/rules/flake8_bandit/rules/shell_injection.rs
robyoung 9d742ce
Address review comment to remove unwraps
robyoung ed510b7
Merge branch 'main' into implement-bandit-shell-injection-rules
charliermarsh a0ae029
Tweak some messages; add test fixtures
charliermarsh 1bda613
Untweak some of those messages
charliermarsh 1a79d26
Use match
charliermarsh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -5,3 +5,4 @@ extend-exclude = ["snapshots", "black"] | |
trivias = "trivias" | ||
hel = "hel" | ||
whos = "whos" | ||
spawnve = "spawnve" |
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
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heads up: I added these here so that they get picked up in the fixture tests (i.e., when running
cargo test
).