Skip to content

ci: make ruff, bandit, and pip-audit blocking and clear findings - #143

Closed
kushaldave002 wants to merge 2 commits into
secfoo-com:mainfrom
kushaldave002:ci/blocking-lint-bandit-audit
Closed

kushaldave002 wants to merge 2 commits into
secfoo-com:mainfrom
kushaldave002:ci/blocking-lint-bandit-audit

Conversation

@kushaldave002

Copy link
Copy Markdown
Contributor

Closes #114

Summary

Clears the existing ruff and bandit backlog, pins ruff==0.17.5 for reproducibility, makes ruff check ., bandit -r src/secfoo -c .bandit -ll, and pip-audit blocking in CI, and updates CONTRIBUTING.md with the pre-PR checklist.

Ruff changes

  • Fixed all auto-fixable findings (UP045, I001, RUF100, FURB167, RUF022, F401, UP037, FURB188), keeping explicit re-export SKILL_ID in src/secfoo/web/sast_dashboard.py with # noqa: F401.
  • Fixed manual findings: EXE001 (chmod +x scripts/sync_design_system.py), PLW1510 (explicit check=False on subprocess.run calls in mcp.py and runner.py), BLE001/S110 (debug logging in runner.py and documented guards in docext.py/templating.py), RUF046 (redundant int(round(...)) in dashboard_common.py), and test cleanups (RUF012, F841, C408, SIM117, RUF059).
  • Configured [tool.ruff.lint.flake8-bugbear].extend-immutable-calls in pyproject.toml for standard FastAPI/Typer defaults (B008), added per-file ignore for PYI034 in src/secfoo/storage/repository.py (typing.Self is Python 3.11+ only and typing_extensions is not a runtime dependency), and pinned ruff==0.17.5.

Bandit review (all 9 findings resolved — 0 remaining across all severities)

Finding Location Resolution Reason
B608 (Medium) src/secfoo/storage/repository.py:559 Annotated (# nosec B608) group_sql is looked up from a fixed 3-key dict right above the query.
B101 (Low) src/secfoo/runner.py:414 Fixed Replaced assert resolved.path is not None with an explicit RuntimeError check that survives python -O.
B110 (Low) src/secfoo/runner.py:150 Fixed Replaced bare except Exception: pass in _try_cloud_sync with logger.debug(..., exc_info=True).
B110 (Low) src/secfoo/runner.py:167 Fixed Replaced bare except Exception: pass in _try_osv_enrich with logger.debug(..., exc_info=True).
B112 (Low) src/secfoo/cli.py:864 Fixed Replaced silent except Exception: continue in runtime OSV recheck loop with log.debug(..., exc_info=True).
B105 (Low) src/secfoo/cli.py:1791 Annotated (# nosec B105) False positive on skill identifier enum value SECRET = "secret-scanning".
B110 (Low) src/secfoo/sensor/probe.py:129 Fixed Replaced bare pass in sensor shutdown handler with _log.debug(..., exc_info=True).
B110 (Low) src/secfoo/sensor/probe.py:157 Annotated (# nosec B110) Last-resort fail-open guard inside _disable() after printing to stderr; must never raise into the host app.
B112 (Low) src/secfoo/sensor/probe.py:345 Fixed Added _log.debug(...) before continue when skipping broken package metadata.

CI & Docs

  • Removed || true from ruff check . in .github/workflows/ci.yml.
  • Added blocking bandit -r src/secfoo -c .bandit -ll and pip-audit steps in .github/workflows/ci.yml.
  • Updated CONTRIBUTING.md to document pytest tests, ruff check ., bandit -r src/secfoo -c .bandit -ll, and pip-audit.

Verification

from dataclasses import dataclass, field

from secfoo.report.sast import SKILL_ID
from secfoo.report.sast import SKILL_ID # noqa: F401 -- re-exported for web.routes.activities
@vsn411

vsn411 commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

Thank you, @kushaldave002. The lint work is solid: ruff check . goes from 135 findings to 0 with no behaviour changes (B008 handled through extend-immutable-calls, side-effecting calls kept, every removed noqa was one ruff flagged as unused), ruff is pinned, and CI now genuinely fails on a new ruff or bandit -ll violation. I'm closing the PR because the dependency audit, the part of #114 that catches real security problems, has a gap that needs a different setup. #114 stays open, and you're very welcome to reopen this PR after pushing the fixes, or open a new one. Reviewed at 8f08f08.

Blocking

  1. pip-audit runs only on Python 3.12, so 3.10 installs go unaudited. This PR's own first CI run (44233090659) failed on py3.10 with "Found 62 known vulnerabilities in 3 packages": pillow 12.3.0 (fixed in 13.0.0), filelock 4.1.0 (4.2.1) and setuptools 79.0.1 (83.0.0 / 84.1.0). requires-python is still >=3.10, and pillow is used at runtime through python-pptx when docext reads uploaded vendor documents. Please audit on 3.10 too, and raise the floors (with environment markers if needed) or record each accepted advisory as below.
  2. The dated, reasoned allowlist from Make lint and security scanning blocking in CI: ruff has 133 errors behind || true, bandit findings are unreviewed, pip-audit never runs #114 isn't there. There's only a comment describing a convention, and it can't work as written: a # date: reason tail on a one-line run: is a YAML comment, and in a run: | block a # ends the shell line. Please add a real file (e.g. .pip-audit-ignore.toml or a small JSON/YAML list of {id, date, reason} read by a script that builds the --ignore-vuln flags), with the 3.10 entries if you decide to accept any.

Should fix

  • The new log calls are invisible. The swallowed failures now log at DEBUG, but secfoo never configures logging, so Python's last-resort handler only shows WARNING and above; a failing cloud sync or OSV recheck thread (cli.py ~L857) is still silent. Use WARNING, or add a log setup / --verbose flag. Please also use a module-level logger = logging.getLogger(__name__) as in runner.py rather than building one inside the loop.
  • The in-process sensor now logs into the host app. In sensor/probe.py (~L348) a package with broken metadata logs a full traceback (exc_info=True) through the application's handlers on every flush, because the failure is never cached in _VERSIONS. The probe is meant to be observe-only; cache the failure and don't log from the probe, or log once.
  • The LOW findings you fixed can come back. bandit -ll blocks MEDIUM and above only, and ruff's rule set has no S101, so a new assert in src/ (the exact runner.py:414 bug fixed here) passes CI. Enable S101 for src/ in ruff, or run bandit at -l for those tests.
  • The assert replacement raises a bare RuntimeError (runner.py ~L415), but secfoo run only catches TargetResolutionError around execute_runs, so a bad target now ends in a traceback after the assessment row was created. Raise TargetResolutionError and add a test for the branch.
  • Two sites still swallow everything without logging: docext.extract_text (~L55) and templating.active_run_count. A pypdf bug would make every vendor document extract as empty with no trace.
  • Only ruff is pinned. bandit and pip-audit stay at >=, and the ruff config relies on ruff's default rule set with no explicit select, so a version bump (including dependabot's grouped pip updates) can change what's enforced and turn unrelated PRs red. Pin both tools and set select explicitly.
  • CONTRIBUTING.md says all four checks run blocking on 3.10 and 3.12; pip-audit runs on 3.12 only. Please make it match whatever you end up with.

Looking forward to the next version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make lint and security scanning blocking in CI: ruff has 133 errors behind || true, bandit findings are unreviewed, pip-audit never runs

3 participants