Skip to content

refactor(security): src has no unreviewed bandit findings: production asserts become raises, partial-path processes resolve their binary, and the password-like and random literals are fixed or justified #1538

Description

@dan-petty

Requested by the owner, 2026-10-10, as part of the bandit coverage decision: bandit covers src/ and tests/ at Medium severity and above, through one shared config for the gate and the code-scanning upload, landing in v0.2.33. The Low findings in src/ get this triage item of their own.

Problem

Checked at release/v0.2.33 (5c5df79) with bandit 1.9.4 (uv run bandit -r src -f json): 184 findings in src/, all Low severity. Until v0.2.33 the gate ran uv run bandit -r src -ll (src/devops_cli/commands/ci.py:455), which hides every Low finding, so nobody has reviewed these.

Rule Count What it is
B101 assert_used 15 assert in production code. Python drops it under -O, so the check silently disappears.
B607 start_process_with_partial_path 3 A process started by bare name, resolved through PATH.
B105/B106/B107 hardcoded password 26 String literals that look like credentials; most are likely names or placeholders.
B311 random 5 The random module; fine unless the value is security-relevant.
B404/B603 subprocess 46 Importing subprocess, and list-form calls without a shell. Inherent to a CLI that runs tools.
B110/B112 swallowed exceptions 89 Already counted and capped by the #1347 ratchet (tests/test_swallowed_failures_ratchet.py:1, ruff S110/S112).

B101 sites:

  • src/devops_cli/ai/benchmark/runner.py:383
  • src/devops_cli/ai/durable.py:135, :154, :178
  • src/devops_cli/roadmap/intake.py:573, :722, :903, :1349, :1414, :1480, :1509
  • src/devops_cli/valkey/client.py:199, :201, :249, :251

B607 sites: src/devops_cli/ai/rag/drift.py:54, src/devops_cli/github/metrics.py:147, :190.

B311 sites: src/devops_cli/ai/benchmark/document_chunker.py:328, src/devops_cli/ai/chaos/injector.py:159, src/devops_cli/ai/rag/embeddings.py:83, :274, src/devops_cli/ai/review/defects.py:1302.

B106/B107 sites: src/devops_cli/k8s/credentials.py:141, src/devops_cli/security/sanitizer.py:340, src/devops_cli/ai/mcp/server.py:1144, src/devops_cli/security/vault_lease.py:190, :204. The 21 B105 sites come from the same command.

Owner decisions

  • Bandit covers src/ and tests/ at Medium and above through one shared config, in v0.2.33 (2026-10-10).
  • The Low findings in src/ are triaged in this item (2026-10-10).

Proposed design

  • B101: each assert becomes an explicit check that raises the module's existing error type (for example ConfigurationError or RoadmapError), or is deleted where a type narrowing already guarantees it. No behaviour change under normal runs; the check now also holds under -O.
  • B607: each call uses the binary constant from src/devops_cli/config/commands.py resolved with shutil.which, as the other tool calls do, and fails with an error naming the missing tool.
  • B105/B106/B107: each literal is checked. A real credential or default secret is removed. A field name, placeholder or token type gets a # nosec B105 <reason> (or B106/B107) on that line.
  • B311: a use whose value never guards anything (chunk sampling, chaos injection, jitter) gets # nosec B311 <reason>; any security-relevant use switches to secrets.
  • B404/B603: stay as they are; they are list-form calls without a shell. The shared bandit config records this as a documented skip for src/ with the reason.
  • B110/B112: stay with the test(cli): swallowed failures may not grow: blind excepts, except-pass, except-continue and unread check=False are held at their ceilings #1347 ratchet.
  • Then the shared config scans src/ at Low too, with only the B404/B603 skip, so new Low findings fail the gate.

Acceptance criteria

  • uv run bandit with the shared config over src/ at Low severity reports zero findings, with only the documented B404/B603 skip; verification: the gate's bandit step on the branch.
  • Every # nosec added names its rule and a reason; verification: git grep -n "# nosec" -- src/ shows no bare marker (a test in tests/test_architectural_invariants.py enforces it).
  • Each replaced assert has a test that hits the failing branch and expects the raised error, run under -n 0.
  • The three B607 calls fail with an error naming the tool when it is missing (tests with the shared executor fake).
  • The test(cli): swallowed failures may not grow: blind excepts, except-pass, except-continue and unread check=False are held at their ceilings #1347 ratchet counts are unchanged or lowered (uv run python tests/test_swallowed_failures_ratchet.py).

Feasibility

Fits one pull request: 15 asserts in four files, three process calls, about 30 literal checks, one config line, and their tests. No new dependency.

Depends on the v0.2.33 bandit coverage change (the shared config). Related: #1347.

Proposed design

Problem statement

The bandit gate ran at Medium severity and above, so all 184 Low findings in src/ were never reviewed. Now that bandit coverage expands to Low in v0.2.33, these findings need triage. Production asserts must become raises so they hold under -O. Partial-path process calls must resolve their binary. Password-like and random literals must be fixed or justified with a reason.

Acceptance criteria

  • Criterion 1: Bandit with the shared config over src/ at Low severity reports zero findings, with only the documented B404/B603 skip.
    Verification: Run the gate's bandit step on the branch and confirm zero findings.
  • Criterion 2: Every # nosec marker added names its rule and a reason.
    Verification: Run git grep -n "# nosec" -- src/ and confirm no bare marker exists. A test in tests/test_architectural_invariants.py enforces this.
  • Criterion 3: Each replaced assert has a test that hits the failing branch and expects the raised error.
    Verification: Run the new tests under -n 0 and confirm they pass.
  • Criterion 4: The three B607 calls fail with an error naming the missing tool when it is absent.
    Verification: Run tests with the shared executor fake that removes the tool from PATH and confirm the error names the tool.
  • Criterion 5: The test(cli): swallowed failures may not grow: blind excepts, except-pass, except-continue and unread check=False are held at their ceilings #1347 ratchet counts are unchanged or lowered.
    Verification: Run uv run python tests/test_swallowed_failures_ratchet.py and confirm it passes.

Key questions

  • Does bandit cover src/ and tests/ at Medium and above through one shared config in v0.2.33?: Yes. The owner decided this on 2026-10-10 as part of the bandit coverage decision. (proposed)
  • Are the Low findings in src/ triaged in this item?: Yes. The owner assigned this triage to this item on 2026-10-10. (proposed)
  • What error type do replaced asserts raise?: Each assert becomes an explicit check that raises the module's existing error type, for example ConfigurationError or RoadmapError. Where a type narrowing already guarantees the condition, the assert is deleted. (proposed)
  • How do the three B607 calls resolve their binary?: Each call uses the binary constant from src/devops_cli/config/commands.py resolved with shutil.which, and fails with an error naming the missing tool. (proposed) [sources: src/devops_cli/config/commands.py]
  • What happens to B404/B603 findings?: They stay as they are. The shared bandit config records a documented skip for src/ with the reason that these are list-form calls without a shell, inherent to a CLI that runs tools. (proposed)
  • What happens to B110/B112 findings?: They stay with the test(cli): swallowed failures may not grow: blind excepts, except-pass, except-continue and unread check=False are held at their ceilings #1347 ratchet in tests/test_swallowed_failures_ratchet.py. (proposed) [sources: tests/test_swallowed_failures_ratchet.py]
  • How many Low findings exist in src/ and what are their rules?: 184 findings, all Low: 15 B101, 3 B607, 26 B105/B106/B107, 5 B311, 46 B404/B603, 89 B110/B112. [sources: src/devops_cli/ai/benchmark/runner.py:383, src/devops_cli/roadmap/intake.py:573, src/devops_cli/valkey/client.py:199, src/devops_cli/ai/rag/drift.py:54, src/devops_cli/github/metrics.py:147, src/devops_cli/ai/benchmark/document_chunker.py:328, src/devops_cli/ai/chaos/injector.py:159, src/devops_cli/ai/rag/embeddings.py:83, src/devops_cli/ai/review/defects.py:1302, src/devops_cli/k8s/credentials.py:141, src/devops_cli/security/sanitizer.py:340, src/devops_cli/security/vault_lease.py:190]
  • Does the work fit one pull request?: Yes. The scope is 15 asserts in four files, three process calls, about 30 literal checks, one config line, and their tests. No new dependency is needed. (proposed)

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    type/refactor
    scope/security
    scope/ci
    on Oct 10, 2026
  2. dan-petty-bot commented on Oct 10, 2026

    @dan-petty-bot
    Collaborator

    Intake placed this item to the backlog: at intake only a critical fix goes into a release; a release start pulls Ready items in, P0 features first.

    • Priority: P2-Medium. All findings are Low severity with no active exploit, but they represent real security-hygiene gaps (asserts vanishing under -O, PATH-resolved binaries) that the owner explicitly scoped for this release.
    • Value: Medium. Hardens the codebase against subtle production failures and credential leakage, but the individual findings are Low severity and many are likely false positives needing only annotation.
    • Effort: Medium. ~23 sites need real code changes (assert→raise, shutil.which) and ~160 need # nosec annotations with reasons, plus a shared bandit config update and a gate tweak.
  3. dan-petty commented on Oct 26, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones on the board.

    • Priority: P1-High. Security fixes are high priority.
    • Value: High. Fixing security issues improves overall project safety and compliance.
    • Effort: Medium. The task involves multiple code changes across several files.
  4. dan-petty commented on Oct 27, 2026

    @dan-petty
    OwnerAuthor

    Status set to Ready at ff47504 (see proposed design in issue body).

  5. added
    priority/p1-high
    status/ready
    effort/medium
    value/high
    on Oct 28, 2026
  6. added a commit that references this issue on Oct 29, 2026
    45261dd
  7. added a commit that references this issue on Oct 29, 2026
  8. removed
    status/ready
    on Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p1-highscope/ciscope/securitytype/refactorvalue/high

    Type

    No type

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions