Skip to content

Commit dc8fda8

Browse files
authored
add bandit, a security linter (#51)
1 parent 42d5525 commit dc8fda8

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,9 @@ repos:
4444
- flake8-comprehensions==3.10.0
4545
- flake8-debugger==4.1.2
4646
- flake8-string-format==0.3.0
47+
- repo: https://github.com/pycqa/bandit
48+
rev: 1.7.4
49+
hooks:
50+
- id: bandit
51+
args: [-c, pyproject.toml]
52+
additional_dependencies: ["toml"]

pyproject.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,7 @@ disable = ["fixme", "missing-class-docstring", "too-many-arguments", "missing-fu
7070
[tool.pylint.variables]
7171
dummy-variables-rgx = "_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_"
7272
ignored-argument-names = "_.*|^ignored_|^unused_|args|kwargs"
73+
74+
[tool.bandit]
75+
exclude_dirs = ["tests"]
76+
skips = ["B101"]

src/iterative_telemetry/__init__.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import logging
77
import os
88
import platform
9-
import subprocess
9+
import subprocess # nosec B404
1010
import sys
1111
import uuid
1212
from functools import lru_cache, wraps
@@ -20,7 +20,7 @@
2020
from filelock import FileLock, Timeout
2121

2222
logger = logging.getLogger(__name__)
23-
TOKEN = "s2s.jtyjusrpsww4k9b76rrjri.bl62fbzrb7nd9n6vn5bpqt"
23+
TOKEN = "s2s.jtyjusrpsww4k9b76rrjri.bl62fbzrb7nd9n6vn5bpqt" # nosec B105
2424
URL = (
2525
"https://iterative-telemetry.herokuapp.com"
2626
"/api/v1/s2s/event?ip_policy=strict"
@@ -168,7 +168,7 @@ def _send_daemon(self, payload):
168168

169169
if os.name == "nt":
170170

171-
from subprocess import (
171+
from subprocess import ( # nosec B404
172172
CREATE_NEW_PROCESS_GROUP,
173173
CREATE_NO_WINDOW,
174174
STARTF_USESHOWWINDOW,
@@ -178,14 +178,16 @@ def _send_daemon(self, payload):
178178
detached_flags = CREATE_NEW_PROCESS_GROUP | CREATE_NO_WINDOW
179179
startupinfo = STARTUPINFO()
180180
startupinfo.dwFlags |= STARTF_USESHOWWINDOW
181-
subprocess.Popen( # pylint: disable=consider-using-with
181+
# pylint: disable=consider-using-with
182+
subprocess.Popen( # nosec B603
182183
[sys.executable, "-c", cmd],
183184
creationflags=detached_flags,
184185
close_fds=True,
185186
startupinfo=startupinfo,
186187
)
187188
elif os.name == "posix":
188-
subprocess.Popen( # pylint: disable=consider-using-with
189+
# pylint: disable=consider-using-with
190+
subprocess.Popen( # nosec B603
189191
[sys.executable, "-c", cmd],
190192
close_fds=True,
191193
)
@@ -280,7 +282,7 @@ def _generate_github_id():
280282
actor = os.environ.get("GITHUB_ACTOR")
281283
group_id = f"{server_url}/{os.path.dirname(repository)}"
282284
try:
283-
user_id = subprocess.check_output(
285+
user_id = subprocess.check_output( # nosec B603, B607
284286
["gh", "api", f"users/{actor}", "--jq", ".name, .login, .id"]
285287
)
286288
except subprocess.SubprocessError:
@@ -313,7 +315,7 @@ def _generate_bitbucket_id():
313315
if not group_id:
314316
return None
315317
try:
316-
user_id = subprocess.check_output(
318+
user_id = subprocess.check_output( # nosec B603, B607
317319
["git", "log", "-1", "--pretty=format:'%ae'"]
318320
)
319321
return group_id, user_id

0 commit comments

Comments
 (0)