Skip to content

Commit 5b00efb

Browse files
committed
Fix up issues found running Bandit on itself
* Used nosec for false various positives. 1. xml.etree is used only for XML generation not parsing 2. "0.0.0.0" is used in the plugin itself 3. Various strings of temp directories are used in the plugin itself. 4. The subprocess call does use user input, but only from the command line itself that is running baseline. Although maybe this could be argued as an issue though. * Fixed the empty try-except-pass to have code in the except block. Fixes #1092 Signed-off-by: Eric Brown <[email protected]>
1 parent a78cafe commit 5b00efb

File tree

5 files changed

+7
-8
lines changed

5 files changed

+7
-8
lines changed

Diff for: bandit/cli/baseline.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import logging
1616
import os
1717
import shutil
18-
import subprocess
18+
import subprocess # nosec: B404
1919
import sys
2020
import tempfile
2121

@@ -101,7 +101,7 @@ def main():
101101
bandit_command = ["bandit"] + step["args"]
102102

103103
try:
104-
output = subprocess.check_output(bandit_command)
104+
output = subprocess.check_output(bandit_command) # nosec: B603
105105
except subprocess.CalledProcessError as e:
106106
output = e.output
107107
return_code = e.returncode

Diff for: bandit/core/utils.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ def get_func_name(node):
6262

6363

6464
def get_qual_attr(node, aliases):
65-
prefix = ""
6665
if isinstance(node, ast.Attribute):
6766
try:
6867
val = deepgetattr(node, "value.id")
@@ -73,7 +72,7 @@ def get_qual_attr(node, aliases):
7372
except Exception:
7473
# NOTE(tkelsey): degrade gracefully when we can't get the fully
7574
# qualified name for an attr, just return its base name.
76-
pass
75+
prefix = ""
7776

7877
return f"{prefix}.{node.attr}"
7978
else:

Diff for: bandit/formatters/xml.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"""
3636
import logging
3737
import sys
38-
from xml.etree import ElementTree as ET
38+
from xml.etree import ElementTree as ET # nosec: B405
3939

4040
from bandit.core import docs_utils
4141

Diff for: bandit/plugins/general_bind_all_interfaces.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
@test.checks("Str")
4444
@test.test_id("B104")
4545
def hardcoded_bind_all_interfaces(context):
46-
if context.string_val == "0.0.0.0":
46+
if context.string_val == "0.0.0.0": # nosec: B104
4747
return bandit.Issue(
4848
severity=bandit.MEDIUM,
4949
confidence=bandit.MEDIUM,

Diff for: bandit/plugins/general_hardcoded_tmp.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959

6060
def gen_config(name):
6161
if name == "hardcoded_tmp_directory":
62-
return {"tmp_dirs": ["/tmp", "/var/tmp", "/dev/shm"]}
62+
return {"tmp_dirs": ["/tmp", "/var/tmp", "/dev/shm"]} # nosec: B108
6363

6464

6565
@test.takes_config
@@ -69,7 +69,7 @@ def hardcoded_tmp_directory(context, config):
6969
if config is not None and "tmp_dirs" in config:
7070
tmp_dirs = config["tmp_dirs"]
7171
else:
72-
tmp_dirs = ["/tmp", "/var/tmp", "/dev/shm"]
72+
tmp_dirs = ["/tmp", "/var/tmp", "/dev/shm"] # nosec: B108
7373

7474
if any(context.string_val.startswith(s) for s in tmp_dirs):
7575
return bandit.Issue(

0 commit comments

Comments
 (0)