Skip to content

chore(security): clear bandit baseline so quality-gate can enforce Security: 0 - #2

Merged
bsbodden merged 1 commit into
mainfrom
chore/bandit-clean-baseline
May 13, 2026
Merged

bsbodden merged 1 commit into
mainfrom
chore/bandit-clean-baseline

Conversation

@bsbodden

Copy link
Copy Markdown
Contributor

Summary

Closes #1.

Takes uv run bandit -r langgoap/ from 17 LOW findings → 0 so the new
PR quality-gate can enforce Security: 0 without false positives.

Strategy

Two project-wide skips for categories that are non-applicable by design,
two narrow code mitigations for the remaining cases.

[tool.bandit] in pyproject.toml

Test ID Reason for skipping
B101 (assert_used) Every assert in langgoap/ is an invariant or type-narrowing guard, never a security check. Bandit's concern (asserts stripped under python -O) is not applicable.
B311 (pseudo-random) The planner is defined by deterministically seedable stochastic search — MCTS rollouts, QoS backoff jitter, transition-model sampling. Cryptographic randomness is inappropriate here.

Code changes

  • langgoap/serde.py — import pickle is gated behind the opt-in pickle_fallback flag. Added a docstring-style comment above the import explaining the gate, plus # nosec B403.
  • langgoap/cli/plan_cmd.py — _auto_explain previously used except Exception: pass (B110). Replaced the bare pass with a logger.debug("auto-explain failed: %s", exc, exc_info=True) call. The CLI still must not crash on explainer edge cases, but failures are now visible under LOG_LEVEL=DEBUG. The finding goes away because the body is no longer just pass.

CI

.github/workflows/test.yml now invokes bandit with -c pyproject.toml so the quality-gate step picks up the new configuration.

Verification

$ uv run bandit -r langgoap/ -c pyproject.toml
[main]	INFO	profile exclude tests: B311,B101
[main]	INFO	using config: pyproject.toml
Run started: 2026-05-13 18:31:36+00:00

Test results:
	No issues identified.

Code scanned:
	Total lines of code: 13831
	Total lines skipped (#nosec): 0
	Total potential issues skipped due to specifically being disabled (e.g., #nosec BXXX): 1
$ uv run pytest -m 'not api'
===================== 1687 passed, 23 deselected in 18.92s =====================

Acceptance criteria checklist

  • uv run bandit -r langgoap/ -c pyproject.toml → 0 results
  • Full pytest suite green (1687 passed)
  • No behavior change in planner, executor, or serializer code paths
  • PR quality-gate will report Security: ✅ Clean (Current: 0) once this lands

Files changed

File Change
pyproject.toml +10 / -0 — new [tool.bandit] section
.github/workflows/test.yml +2 / -2 — pass -c pyproject.toml to bandit
langgoap/serde.py +5 / -1 — rationale comment + # nosec B403
langgoap/cli/plan_cmd.py +7 / -2 — logger + logger.debug in lieu of pass

@bsbodden bsbodden added the enhancement New feature or request label May 13, 2026
@bsbodden bsbodden self-assigned this May 13, 2026
…lity

Three coordinated changes that together let the new PR quality-gate
enforce Security: 0 across the full Ubuntu / macOS / Windows matrix.

1. Bandit clean baseline (Security: 0)
   Take `bandit -r langgoap/` from 17 LOW findings to 0 by combining a
   narrow `[tool.bandit]` configuration with two per-line markers.

     B101 (assert_used)    Every assert in langgoap/ is an invariant or
                           type-narrowing guard, not a security check.
                           Bandit's concern (asserts stripped under -O)
                           is not applicable.
     B311 (pseudo-random)  The planner is defined by deterministically
                           seedable stochastic search (MCTS rollouts,
                           QoS jitter, transition sampling).  Crypto
                           randomness is inappropriate.

   serde.py        `import pickle` is gated behind the opt-in
                   `pickle_fallback` flag.  Documented inline and
                   marked `# nosec B403`.
   cli/plan_cmd.py `_auto_explain` previously swallowed exceptions
                   with `except Exception: pass` (B110).  Replaced the
                   bare `pass` with a `logger.debug(...)` call so
                   failures surface under LOG_LEVEL=DEBUG.

   test.yml quality-gate now invokes bandit with `-c pyproject.toml`.

2. Multi-OS test exclusions
   GitHub-hosted Windows *and* macOS runners ship without a Docker
   daemon, so testcontainers-based Postgres/Redis tests in
   tests/integration/test_checkpointing.py cannot run.  Broaden the
   existing windows-only ignore so any non-Linux runner skips that
   file.

3. Windows file-encoding portability
   CPython on Windows defaults to cp1252 for text I/O, which breaks
   our CLI write paths and the LangGraph deployment scaffold on UTF-8
   content.  Add explicit `encoding="utf-8"` to:

     - langgoap/cli/plan_cmd.py        (`open(out, "w")`)
     - langgoap/cli/visualize_cmd.py   (`open(out, "w")`)
     - langgoap/cli/_loader.py         (`open(path)` for JSON)
     - langgoap/integrations/langgraph_deploy.py (`path.write_text`)

Verification:
  uv run bandit -r langgoap/ -c pyproject.toml  -> No issues identified
  uv run pytest -m 'not api'                    -> 1687 passed
  Ubuntu / macOS / Windows runners are now expected to pass.

Closes #1
@bsbodden
bsbodden force-pushed the chore/bandit-clean-baseline branch from 3fa4586 to 89cd92e Compare May 13, 2026 18:54
@github-actions

Copy link
Copy Markdown

✅ Code Quality Report

Metric Score Status
MFCQI Score 0.8203666241704082 ✅ Good
Test Coverage 93% ✅ Good
Security Issues 0 ✅ Clean

Quality Gates

  • MFCQI Score: ✅ Minimum 0.75 (Current: 0.8203666241704082)
  • Test Coverage: ✅ Minimum 80% (Current: 93%)
  • Security: ✅ Zero vulnerabilities (Current: 0)

🎉 All quality gates passed! This PR maintains high code quality standards.

📊 View detailed MFCQI breakdown

Run uv run python -m mfcqi analyze langgoap locally to see detailed metrics breakdown.

@bsbodden
bsbodden merged commit 655fe91 into main May 13, 2026
18 checks passed
@bsbodden
bsbodden deleted the chore/bandit-clean-baseline branch May 13, 2026 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Take bandit baseline from 17 LOW findings to 0

1 participant