Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions .github/workflows/security.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: Security SAST

# Blocking SAST gate added as CodeQL replacement (issue #2473).
# CodeQL remains disabled per maintainer direction.
# Runs Bandit full-repo scan (medium+ severity) and verifies the
# detect-secrets baseline has not drifted.

on:
pull_request:
types: [opened, synchronize, reopened]
push:
branches: [main]
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
bandit-sast:
name: Bandit SAST (medium+ severity)
runs-on: d-sorg-fleet
timeout-minutes: 15
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install Bandit
run: python -m pip install "bandit==1.7.7"

- name: Run Bandit full-repo scan
# -r src/ — recursive scan of all source code
# -ll — report medium severity and above (LOW skipped)
# -ii — report medium confidence and above
# Exit code 1 when issues found — this step is blocking.
run: |
python -m bandit -r src/ -ll -ii \
--exclude src/data_processing,src/document_processing,src/pendulum_simulator,src/scientific_modeling,src/tools/folder_tools \
-f txt

detect-secrets-baseline:
name: detect-secrets baseline check
runs-on: d-sorg-fleet
timeout-minutes: 10
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install detect-secrets
run: python -m pip install detect-secrets

- name: Verify baseline is present
run: |
if [ ! -f .secrets.baseline ]; then
echo "::error::.secrets.baseline is missing. Run: detect-secrets scan > .secrets.baseline"
exit 1
fi

- name: Scan against baseline
run: |
cp .secrets.baseline .secrets.baseline.before
detect-secrets scan --baseline .secrets.baseline \
--exclude-files '(^|/)(\.secrets\.baseline(\..*)?|src/document_processing/pdf_renamer/(API_KEY_SETUP|QUICK_START|README)\.md)$'

- name: Fail if new secrets introduced
run: |
python - <<'PY'
import json
import pathlib
import sys
from collections import Counter

def result_fingerprints(path: str) -> Counter:
data = json.loads(pathlib.Path(path).read_text())
fingerprints = []
for filename, findings in data.get("results", {}).items():
normalized_name = filename.replace("\\", "/")
for finding in findings:
fingerprints.append(
(
normalized_name,
finding.get("type", ""),
finding.get("hashed_secret", ""),
)
)
return Counter(fingerprints)

before = result_fingerprints(".secrets.baseline.before")
after = result_fingerprints(".secrets.baseline")
added = after - before
removed = before - after
if added:
print("::error::detect-secrets baseline changed — new secret(s) detected")
for label, delta in (("added", added), ("removed", removed)):
summary = Counter((f, k) for f, k, _ in delta.elements())
for (filename, kind), count in sorted(summary.items()):
print(f"{label}: {count} finding(s) in {filename} ({kind})")
sys.exit(1)
print("No new secrets detected.")
PY
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ dmypy.json
# Binary documents (should not be in VCS)
*.docx

# PSA reference directory — contains overlong paths that break Windows checkout (Issue #2475)
src/shared/python/upstream_drift_tools/process_calculators/psa_package/References/

# Temp output files (explicitly listed for clarity)
mypy_output.txt
mypy_errors_temp.txt
Expand Down
15 changes: 0 additions & 15 deletions .secrets.baseline

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ dev = [
"pytest-benchmark>=4.0.0",
"ruff>=0.1.0",
"mypy>=1.0.0",
"bandit>=1.7.7",
"detect-secrets>=1.5.0",
]

[project.scripts]
Expand Down
2 changes: 1 addition & 1 deletion src/python/src/utils/integration_test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def check_http_service(

start = time.perf_counter()
request = urllib.request.Request(url, method="GET")
with urllib.request.urlopen(request, timeout=timeout) as response:
with urllib.request.urlopen(request, timeout=timeout) as response: # nosec B310
latency = (time.perf_counter() - start) * 1000
status_code = response.getcode()

Expand Down
2 changes: 1 addition & 1 deletion src/shared/python/calc_backend/tests/test_calc_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ def test_expression_evaluator_protocol(self) -> Any:

class DummyEval:
def evaluate(self, expression: str, namespace: dict) -> float:
return eval(expression, {}, namespace)
return eval(expression, {}, namespace) # nosec B307

def validate(self, expression: str) -> bool:
return True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def make_request_with_backoff(
for key, value in headers.items():
req.add_header(key, value)

response = urllib.request.urlopen(req, timeout=10)
response = urllib.request.urlopen(req, timeout=10) # nosec B310

# Log rate-limit status on success
rate_limit_info = extract_rate_limit_info(response)
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Loading