Skip to content

Commit 74b53ce

Browse files
fix: improve bandit config (re-enable B608)
* fixes #3830 Co-authored-by: harshittiwariii <[email protected]>
1 parent 9438376 commit 74b53ce

7 files changed

+14
-15
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ repos:
3030
rev: 7.0.0
3131
hooks:
3232
- id: flake8
33-
exclude: ^fuzz/generated/
33+
exclude: ^fuzz/generated/|bandit\.conf$
3434

3535
- repo: https://github.com/PyCQA/bandit
3636
rev: 1.7.7

bandit.conf

+4-5
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,14 @@
8282
# B703 : django_mark_safe
8383

8484
# (optional) list included test IDs here, eg '[B101, B406]':
85-
tests:
85+
#tests:
8686

8787
# (optional) list skipped test IDs here, eg '[B101, B406]':
88-
skips: ['B603', 'B607', 'B404', "B608"]
88+
skips: ['B603', 'B607', 'B404']
8989
# B603, B607 and B404 are all subprocess-related.
9090
# B608 should be re-enabled when multi-line issues can be marked with nosec
9191

92-
# Explantion: cve-bin-tool is at heart a shell script that calls other processes.
92+
# Explanation: cve-bin-tool is at heart a shell script that calls other processes.
9393
# Switching to pure python has significant performance impacts.
9494

9595
# skips assert rule on tests
@@ -100,5 +100,4 @@ assert_used:
100100
### that may be given here, per-plugin. All bandit test plugins have a built in
101101
### set of sensible defaults and these will be used if no configuration is
102102
### provided. It is not necessary to provide settings for every (or any) plugin
103-
### if the defaults are acceptable.
104-
103+
### if the defaults are acceptable.

cve_bin_tool/cve_scanner.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def get_cves(self, product_info: ProductInfo, triage_data: TriageData):
200200
FROM cve_severity
201201
WHERE CVE_number IN ({",".join(["?"] * number_of_cves)}) AND score >= ? and description != "unknown"
202202
ORDER BY CVE_number, last_modified DESC
203-
"""
203+
""" # nosec
204204
# Add score parameter to tuple listing CVEs to pass to query
205205
result = self.cursor.execute(query, cve_list[start:end] + [self.score])
206206
start = end

cve_bin_tool/cvedb.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def latest_schema(
253253

254254
self.LOGGER.debug("Check database is using latest schema")
255255
cursor = self.db_open_and_get_cursor()
256-
schema_check = f"SELECT * FROM {table_name} WHERE 1=0"
256+
schema_check = f"SELECT * FROM {table_name} WHERE 1=0" # nosec
257257
result = cursor.execute(schema_check)
258258
schema_latest = False
259259

@@ -865,7 +865,7 @@ def get_all_records_in_table(self, table_name):
865865
"""Return JSON of all records in a database table."""
866866
cursor = self.db_open_and_get_cursor()
867867
cursor.row_factory = self.dict_factory
868-
cursor.execute(f"SELECT * FROM '{table_name}' ")
868+
cursor.execute(f"SELECT * FROM '{table_name}' ") # nosec
869869
# fetchall as result
870870
results = cursor.fetchall()
871871
self.db_close()

cve_bin_tool/version_signature.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def get_mapping_data(self):
7777
update_required: bool = False
7878

7979
datestamp = self.cursor.execute(
80-
f"SELECT * FROM {self.update_table_name}"
80+
f"SELECT * FROM {self.update_table_name}" # nosec
8181
).fetchone() # update_table_name validated in __init__
8282

8383
if datestamp and type(datestamp) is tuple:
@@ -93,18 +93,18 @@ def get_mapping_data(self):
9393
self.cursor.execute(f"DELETE FROM {self.table_name}") # nosec
9494
self.cursor.execute(f"DELETE FROM {self.update_table_name}") # nosec
9595
self.cursor.execute(
96-
f"INSERT INTO {self.update_table_name} VALUES (?)",
96+
f"INSERT INTO {self.update_table_name} VALUES (?)", # nosec
9797
(time.time(),),
9898
)
9999

100100
for mapping in self.mapping_function():
101101
self.cursor.execute(
102-
f"INSERT INTO {self.table_name} (version, sourceId) VALUES (?, ?)",
102+
f"INSERT INTO {self.table_name} (version, sourceId) VALUES (?, ?)", # nosec
103103
(mapping[0], mapping[1]),
104104
)
105105

106106
data = self.cursor.execute(
107-
f"SELECT * FROM {self.table_name}"
107+
f"SELECT * FROM {self.table_name}" # nosec
108108
).fetchall() # table_name validated in __init__
109109

110110
if self.conn is not None:

setup.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
profile = black
33

44
[flake8]
5-
exclude = build
5+
exclude = build, bandit.conf
66
max-line-length = 88
77
extend-ignore = E203, E501
88

test/test_cvedb.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def test_new_database_schema(self):
8080

8181
for table in tables_to_check:
8282
cursor.execute(
83-
f"SELECT name FROM sqlite_master WHERE type='table' AND name='{table}'"
83+
"SELECT name FROM sqlite_master WHERE type='table' AND name=?", (table,)
8484
)
8585
result = cursor.fetchone()
8686
assert result is not None # Assert that the table exists

0 commit comments

Comments
 (0)