Skip to content

Commit 7d15f64

Browse files
committed
Merge branch 'main' into plugin_unit_tests
Signed-off-by: Eric Brown <[email protected]>
2 parents 31da3fe + ff431af commit 7d15f64

40 files changed

+2360
-265
lines changed

.github/ISSUE_TEMPLATE/bug-report.yml

+9-7
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ body:
4444
label: Bandit version
4545
description: Run "bandit --version" if unsure of version number
4646
options:
47-
- 1.7.4 (Default)
47+
- 1.7.5 (Default)
48+
- 1.7.4
4849
- 1.7.3
4950
- 1.7.2
5051
- 1.7.1
@@ -67,12 +68,13 @@ body:
6768
label: Python version
6869
description: Run "bandit --version" if unsure of version number
6970
options:
70-
- 3.10 (Default)
71-
- 3.9
72-
- 3.8
73-
- 3.7
74-
- 3.6
75-
- 3.5
71+
- "3.11 (Default)"
72+
- "3.10"
73+
- "3.9"
74+
- "3.8"
75+
- "3.7"
76+
- "3.6"
77+
- "3.5"
7678
validations:
7779
required: true
7880

.github/dependabot.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
version: 2
3+
updates:
4+
- package-ecosystem: "github-actions"
5+
directory: "/"
6+
interval:
7+
schedule: "monthly"

.github/workflows/pythonpackage.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ jobs:
5151
strategy:
5252
matrix:
5353
python-version: [
54-
["3.7", "37"], ["3.8", "38"], ["3.9", "39"], ["3.10", "310"], ["3.11.0-a - 3.11", "311"]
54+
["3.7", "37"], ["3.8", "38"], ["3.9", "39"], ["3.10", "310"], ["3.11", "311"]
5555
]
5656
os: [ubuntu-latest, macos-latest]
5757
runs-on: ${{ matrix.os }}

README.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
======
55

6-
.. image:: https://github.com/PyCQA/bandit/workflows/Build%20and%20Test%20Bandit/badge.svg
7-
:target: https://github.com/PyCQA/bandit/actions?query=workflow%3A%22Build+and+Test+Bandit%22
6+
.. image:: https://github.com/PyCQA/bandit/actions/workflows/pythonpackage.yml/badge.svg?branch=main
7+
:target: https://github.com/PyCQA/bandit/actions?query=workflow%3A%22Build+and+Test+Bandit%22+branch%3Amain
88
:alt: Build Status
99

1010
.. image:: https://readthedocs.org/projects/bandit/badge/?version=latest

bandit/blacklists/calls.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
1010
This blacklist data checks for a number of Python calls known to have possible
1111
security implications. The following blacklist tests are run against any
12-
function calls encoutered in the scanned code base, triggered by encoutering
12+
function calls encountered in the scanned code base, triggered by encoutering
1313
ast.Call nodes.
1414
1515
B301: pickle

bandit/core/node_visitor.py

-7
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,6 @@ def pre_visit(self, node):
200200
if hasattr(node, "lineno"):
201201
self.context["lineno"] = node.lineno
202202

203-
# explicitly check for empty set to skip all tests for a line
204-
nosec_tests = self.nosec_lines.get(node.lineno)
205-
if nosec_tests is not None and not len(nosec_tests):
206-
LOG.debug("skipped, nosec without test number")
207-
self.metrics.note_nosec()
208-
return False
209-
210203
if hasattr(node, "col_offset"):
211204
self.context["col_offset"] = node.col_offset
212205
if hasattr(node, "end_col_offset"):

bandit/core/tester.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,15 @@ def run_tests(self, raw_context, checktype):
7676

7777
# don't skip the test if there was no nosec comment
7878
if nosec_tests_to_skip is not None:
79-
# if the set is empty or the test id is in the set of
80-
# tests to skip, log and increment the skip by test
81-
# count
82-
if not nosec_tests_to_skip or (
83-
result.test_id in nosec_tests_to_skip
84-
):
79+
# If the set is empty then it means that nosec was
80+
# used without test number -> update nosecs counter.
81+
# If the test id is in the set of tests to skip,
82+
# log and increment the skip by test count.
83+
if not nosec_tests_to_skip:
84+
LOG.debug("skipped, nosec without test number")
85+
self.metrics.note_nosec()
86+
continue
87+
elif result.test_id in nosec_tests_to_skip:
8588
LOG.debug(
8689
"skipped, nosec for test %s" % result.test_id
8790
)
@@ -129,7 +132,7 @@ def _get_nosecs_from_contexts(self, context, test_result=None):
129132
if test_result
130133
else None
131134
)
132-
context_tests = self.nosec_lines.get(context["lineno"], None)
135+
context_tests = utils.get_nosec(self.nosec_lines, context)
133136

134137
# if both are none there were no comments
135138
# this is explicitly different from being empty.

bandit/core/utils.py

+8
Original file line numberDiff line numberDiff line change
@@ -370,3 +370,11 @@ def check_ast_node(name):
370370
pass
371371

372372
raise TypeError("Error: %s is not a valid node type in AST" % name)
373+
374+
375+
def get_nosec(nosec_lines, context):
376+
for lineno in context["linerange"]:
377+
nosec = nosec_lines.get(lineno, None)
378+
if nosec is not None:
379+
return nosec
380+
return None

bandit/formatters/xml.py

-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
New field `CWE` added to output
3434
3535
"""
36-
# This future import is necessary here due to the xml import below on Python
37-
# 2.7
3836
import logging
3937
import sys
4038
from xml.etree import cElementTree as ET

bandit/plugins/exec.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
CWE: CWE-78 (https://cwe.mitre.org/data/definitions/78.html)
2020
Location: ./examples/exec.py:2
2121
1 exec("do evil")
22-
2 exec "do evil"
22+
2323
2424
.. seealso::
2525

bandit/plugins/injection_sql.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,18 @@ def _evaluate_ast(node):
9292
elif hasattr(ast, "JoinedStr") and isinstance(
9393
node._bandit_parent, ast.JoinedStr
9494
):
95-
statement = node.s
96-
wrapper = node._bandit_parent._bandit_parent
95+
substrings = [
96+
child
97+
for child in node._bandit_parent.values
98+
if isinstance(child, ast.Str)
99+
]
100+
# JoinedStr consists of list of Constant and FormattedValue
101+
# instances. Let's perform one test for the whole string
102+
# and abandon all parts except the first one to raise one
103+
# failed test instead of many for the same SQL statement.
104+
if substrings and node == substrings[0]:
105+
statement = "".join([str(child.s) for child in substrings])
106+
wrapper = node._bandit_parent._bandit_parent
97107

98108
if isinstance(wrapper, ast.Call): # wrapped in "execute" call?
99109
names = ["execute", "executemany"]

0 commit comments

Comments
 (0)