Skip to content

Commit 6587ac4

Browse files
authored
ci: integrate Bandit security scanning & fix initial findings (#18)
* ci(bandit): add bandit for security scanning and format/de-lint ci.yaml * fix(security): enable Jinja2 autoescape in PlanReporter (resolves Bandit B701) Bandit flagged B701 because Jinja2’s Environment defaulted to autoescape=False. Setting autoescape=True prevents potential XSS issues when rendering templates * test: de-lint test_cli
1 parent dd2e348 commit 6587ac4

File tree

4 files changed

+36
-31
lines changed

4 files changed

+36
-31
lines changed

.github/workflows/ci.yaml

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: CI
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches: [main]
66
pull_request:
7-
branches: [ main ]
7+
branches: [main]
88

99
jobs:
1010
test:
@@ -14,32 +14,33 @@ jobs:
1414
python-version: ["3.10", "3.11", "3.12", "3.13"]
1515

1616
steps:
17-
- uses: actions/checkout@v4
18-
19-
- name: Set up Python ${{ matrix.python-version }}
20-
uses: actions/setup-python@v5
21-
with:
22-
python-version: ${{ matrix.python-version }}
23-
24-
- name: Install dependencies
25-
run: |
26-
python -m pip install --upgrade pip
27-
pip install poetry twine
28-
poetry install --with dev
29-
30-
- name: Lint with Ruff
31-
run: poetry run ruff check .
32-
33-
- name: Run tests with coverage
34-
run: |
35-
poetry run pytest --cov=tfsumpy --cov-report=term
36-
poetry run coverage report --fail-under=75
37-
38-
- name: Coverage reminder
39-
if: success()
40-
run: echo "::notice ::Current threshold is 75%. PRs that raise coverage are welcome!"
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up Python ${{ matrix.python-version }}
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: ${{ matrix.python-version }}
23+
24+
- name: Install dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install poetry twine bandit
28+
poetry install --with dev
29+
30+
- name: Lint with Ruff
31+
run: poetry run ruff check .
4132

42-
- name: Build package
43-
run: poetry build
33+
- name: Security scan with Bandit
34+
run: poetry run bandit -q -r tfsumpy -llst
35+
36+
- name: Run tests with coverage
37+
run: |
38+
poetry run pytest --cov=tfsumpy --cov-report=term
39+
poetry run coverage report --fail-under=75
40+
41+
- name: Coverage reminder
42+
if: success()
43+
run: echo "::notice ::Current threshold is 75%. PRs that raise coverage are welcome!"
4444

45-
45+
- name: Build package
46+
run: poetry build

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,14 @@ ruff = ">=0.4.0"
4545
mypy = ">=1.10.0"
4646
types-colorama = "*"
4747
coverage = ">=7.2.0"
48+
bandit = ">=1.7.8"
4849

4950
[tool.poetry.extras]
5051
dev = [
5152
"pytest-cov",
5253
"pytest-mock",
5354
"coverage",
55+
"bandit",
5456
"ruff",
5557
"mypy"
5658
]
@@ -60,4 +62,4 @@ tfsumpy = "tfsumpy.__main__:main"
6062

6163
[build-system]
6264
requires = ["poetry-core"]
63-
build-backend = "poetry.core.masonry.api"
65+
build-backend = "poetry.core.masonry.api"

tests/test_cli.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import subprocess, sys, json
1+
import subprocess
2+
import sys
23

34
def test_cli_smoke():
45
result = subprocess.run(

tfsumpy/plan/reporter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def __init__(self):
1717
# Initialize Jinja2 environment
1818
template_dir = Path(__file__).parent.parent / 'templates'
1919
self.env = Environment(
20+
autoescape=True,
2021
loader=FileSystemLoader(str(template_dir)),
2122
trim_blocks=True,
2223
lstrip_blocks=True

0 commit comments

Comments
 (0)