Skip to content

bitwarden-load-secrets: multiline values are split into bogus variables #5650

Closed

Description

@dezren39

Finding

bitwarden-load-secrets.sh stores secret records in a newline-delimited PAIRS string (lib/bitwarden-load-secrets.sh:185-196). The BWS and Vault loaders emit raw jq values into tab/newline-delimited records (:223-225, :271-273), and each output mode later reads PAIRS one line at a time (:304-310, :315-320, :323-329). A newline inside a legitimate secret therefore becomes another record instead of remaining part of that secret.

Reproduced with a stub bws returning TLS_CERT = "BEGIN CERT\\nPRIVATE KEY\\nEND CERT": --format json produced TLS_CERT: "BEGIN CERT", plus bogus empty PRIVATE_KEY and END_CERT entries. The script documents direct CLI and sourced use (:5-8, :110-113); no in-repository callers or tests were found.

Why it matters

Multiline values such as private keys and certificates are silently truncated, so consumers receive invalid credentials; continuation text is also exposed as unintended environment-variable names in source/export modes. This is a functional defect in the loader's documented use.

Suggested fix

Keep key/value pairs in a representation that preserves newlines (rather than embedding raw values in a newline-delimited string), and add regression coverage for multiline values across the supported output formats. Shell output values are currently quoted; this finding is about record corruption, not a demonstrated shell-injection path.

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    area/infraInfrastructure, deployment, and operations
    effort/sSmall: expected under 2 hours of work
    on Nov 4, 2026
  2. developing-today commented on Nov 4, 2026

    @developing-today
    Contributor
  3. added
    task/triageQueue packet kind: verify, reproduce, and route this item
    on Nov 5, 2026
  4. dezren39 commented on Nov 5, 2026

    @dezren39
    MemberAuthor

    Triage outcome — task 10098 (2026-11-05, lane code-p)

    Verdict: CONFIRMED on current main — reproduced exactly as filed; fix path scoped, follow-up fix task enqueued.

    Fresh verification (2026-11-05): issue #5650 OPEN, labels kind/bug, task/triage, area/infra, effort/s — no held / user/owned / do-not-merge / do-not-auto-edit labels. No competing or duplicate work: no open PR touches lib/bitwarden-load-secrets.sh, an issue search returns only #5650 itself, and git grep on origin/main finds no in-repo callers or tests for the script.

    Code read (origin/main 04f78696ab, lib/bitwarden-load-secrets.sh): PAIRS is a newline-delimited KEY<TAB>VALUE string (:185-196, add_pair appends the raw value). The corruption has TWO stages, and a fix must cover both:

    1. Loader stage — the BWS list loader (:223-225) and the Vault custom-fields loader (:271-273) read jq -r output with while IFS=$'\t' read -r k v, one line at a time: a multiline value is already split there, before PAIRS is involved.
    2. Storage/output stage — single-value paths (:215, :247-287) preserve the multiline value into add_pair, but every output mode re-reads PAIRS line-by-line (source :304-310, export :315-320, env :323-329) and json mode splits each input line on tab (:330-338), splitting the value again.

    Reproduction (laptop probe ~/git/fleet/probe-5650, real script from laptop main 04f78696ab, stub bws): secret TLS_CERT = "BEGIN CERT\nPRIVATE KEY\nEND CERT" plus a sane PLAIN=hello control —

    • --bws --format json → TLS_CERT: "BEGIN CERT" plus bogus "PRIVATE_KEY": "" and "END_CERT": "" entries (sanitized from the continuation lines); control intact.
    • --bws --format export → export TLS_CERT='BEGIN CERT' plus bogus export PRIVATE_KEY= / export END_CERT=.

    Matches the filing exactly (the filed repro's variable spellings differ only by the sanitizer's space handling).

    Fix path (scoped for the follow-up task): give key/value records a newline-safe representation end-to-end — e.g. loaders emit the value base64-encoded (jq @base64) so the read loops never see a raw newline, PAIRS stores the encoded value, and each output mode decodes before quoting/export (json mode decodes so the emitted JSON carries the true multiline string). Any representation with the same property is acceptable; patching only the output readers is NOT sufficient (stage 1 above). Regression coverage: a stub-bws test with a multiline value plus a sane control, asserted across json/export/env (and source-mode variable values), failing pre-fix and passing post-fix. No in-repo callers or existing tests constrain the internal representation.

    agent-note:v1
    {"kind": "triage", "task": 10098, "issue": 5650, "state": "done", "outcome": "confirmed_reproduced_fix_scoped", "evidence": "main 04f7869; PAIRS newline-delimited at lib/bitwarden-load-secrets.sh:185-196; loader read loops :223-225/:271-273; laptop probe reproduced bogus PRIVATE_KEY/END_CERT in json+export"}

  5. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed on Nov 5, 2026
  6. dezren39 commented on Nov 5, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up

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

    @dezren39
    MemberAuthor

    🤖 Agent note · done

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

Metadata

Metadata

Assignees

Labels

area/infraInfrastructure, deployment, and operationseffort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)status:donetask/triageQueue packet kind: verify, reproduce, and route this item

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions