Skip to content

bitwarden-load-secrets: value-taking options hang forever on a trailing flag and swallow a following flag as the value #6932

Closed

Description

@dezren39

Summary

lib/bitwarden-load-secrets.sh parses every value-taking option with an
unguarded "$2" + shift 2 (lines 44, 48, 81, 86, 90, 94: --item,
--field, --secret, --project, --prefix, --format). The script has
no set -u and no value check, so:

  1. A trailing value-option hangs forever. With --item as the last
    argument, $# is 1, ITEM_QUERY="$2" reads empty, and shift 2 fails
    without advancing the positional parameters — the while [[ $# -gt 0 ]]
    loop repeats the same iteration indefinitely. When the script is
    sourced (its primary documented mode), this hangs the caller's shell.
  2. A flag in the value position is swallowed as the value.
    --item --bws sets ITEM_QUERY="--bws" and consumes the flag: the
    script silently runs in vault mode against an item literally named
    --bws instead of switching to Secrets Manager mode (or erroring).

This is the same missing/flag-like-value defect class fixed for the
aggregator scripts in #6926/#6922/#6930 and for record-claude-launch in
#6895, but here the failure mode is worse: an infinite loop instead of a
wrong record.

Evidence (verified this run, laptop main @4c3d00ccb7)

Probe: ~/git/fleet/probe-bw-load-args (real script verbatim, stub bw/bws
first on PATH, HOME pointed at an empty dir so the script's
~/.local/bin prepend cannot shadow the stubs):

  • Control --item StubItem --format json → rc 0, prints
    {"API_KEY": "sekrit"} from the stub item.
  • bash lib/bitwarden-load-secrets.sh --item → never returns; killed by
    timeout 3 (rc 124).
  • bash lib/bitwarden-load-secrets.sh --item StubItem --format → same
    hang (rc 124).
  • bash lib/bitwarden-load-secrets.sh --item --bws → rc 0 in vault
    mode, exporting the stub item's field (export API_KEY='sekrit'); the
    --bws flag was consumed as the item name and Secrets Manager mode
    never engaged.

The existing contract suite scripts/tests/test_bitwarden_load_secrets.py
(4 tests, from #5650) covers multiline values only — no missing-value or
flag-as-value case.

Why it matters

This loader is sourced into shells to fetch credentials; a typo'd command
(source lib/bitwarden-load-secrets.sh --item) freezes the user's shell
with no message, and --item --bws-style slips silently query the wrong
backend/item instead of failing fast like every sibling script now does.

Acceptance criteria

  • Each value-taking option (--item, --field, --secret, --project,
    --prefix, --format) with a missing, empty, or flag-like (--*)
    value fails fast with a usage error naming the option — exit non-zero
    when executed, and abort the source with non-zero status when sourced;
    never loop.
  • Valid invocations are unchanged (all 4 existing tests in
    scripts/tests/test_bitwarden_load_secrets.py still pass).
  • New regression tests in that suite cover at least: trailing --item,
    trailing --format, and --item --bws (flag-as-value), each completing
    under a timeout with a non-zero status and an error naming the option.

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests
    source/creatorFiled by the new-issue-creator job
    on Nov 7, 2026
  2. developing-today commented on Nov 7, 2026

    @developing-today
    Contributor
  3. added
    priority/normalOrdinary priority (the default)
    area/infraInfrastructure, deployment, and operations
    work/self-assignedAn agent grabbed this item directly, outside the queue
    on Nov 7, 2026
  4. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    State: filed this run by new-issue-creator-code-b; taking the guarded self-solve path (trivial, clearly scoped, low-risk — the same guard pattern as #6926/#6922/#6930). Branch creator-b/6932-bw-load-args-guard in a laptop worktree; fix + regression tests to follow, PR will reference this issue.

    Found via: filed this run — verified on laptop main @4c3d00ccb7 with probe ~/git/fleet/probe-bw-load-args (real script, stub bw/bws): trailing --item and trailing --format hang (timeout rc 124), --item --bws swallows the flag as the item name and runs in vault mode rc 0; control invocation rc 0 with correct output.

  5. added a commit that references this issue on Nov 7, 2026
  6. dezren39 commented on Nov 7, 2026

    @dezren39
    MemberAuthor

    Done: PR #6933 merged as def55ca. All six value-taking options now fail fast on a missing/empty/flag-like value; suite 8/8 on merged main (new tests fail/timeout pre-fix: 3 failures + 3 errors); probe re-run on merged main: trailing --item exits 1 naming the option, control invocation unchanged.

  7. added and removed
    work/self-assignedAn agent grabbed this item directly, outside the queue
    on Nov 7, 2026
  8. added 2 commits that reference this issue on Nov 10, 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

    area/infraInfrastructure, deployment, and operationskind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobstatus:donetask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions