Skip to content

fix: keep secrets with quotes, backslashes or newlines alive in a passwordless GNOME keyring - #168

Merged
I4cTime merged 9 commits into
mainfrom
feat/keyring-safe-envelope
Nov 14, 2026
Merged

I4cTime merged 9 commits into
mainfrom
feat/keyring-safe-envelope

Conversation

@I4cTime

@I4cTime I4cTime commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

A GNOME keyring without a password is kept as a plain text file. The daemon writes each secret raw and reads the file back with escape processing. A q-ring entry whose stored JSON carried a backslash escape (a double quote, backslash, newline or control character in the value, a description or a tag) came back empty the next time the daemon reloaded its file, often right after the next keyring write. A newline escape made the daemon reject the whole file, so every secret in that keyring became unreadable. q-ring then read the empty string as a plain value and rewrote an empty envelope over it, which hid the loss.

This PR:

  • stores such an envelope on Linux in a backslash-free safe form, {"v":1,"enc":"b64","data":"<base64 of the envelope JSON>"}. Envelopes that need no escape are stored byte for byte as before. Every platform reads both forms.
  • makes an empty stored string an error (EmptyStoredValueError) on reads instead of a plain value. Such a key counts as absent for has, import --skip-existing and lint --fix (so they store the value again), can be set again or deleted, is marked in list, list --json and MCP list_secrets, and is skipped with a warning by export and exec (MCP exec_with_secrets names the skipped keys in its note).
  • rescues an entry the keyring empties between q-ring's read and its write-back: the envelope already in hand is written back in the safe form.
  • adds a qring doctor check, "keyring storage format": warns when the default GNOME keyring is the passwordless plain text kind and lists keys still stored in the at-risk form and keys that are already empty, for global scope and the current project. qring doctor --fix rewrites the at-risk entries in one pass from a single snapshot, without printing values, counting a read or tripping a canary. The check reads only the first 16 bytes of the keyring file and runs before doctor's own keyring probe.
  • documents the format in docs/stability.md (amended before the code, twice), with changelog entries and a troubleshooting section.

Type

  • Feature
  • Fix
  • Security
  • Docs
  • Chore / CI / deps

Checklist

  • pnpm run typecheck passes
  • pnpm run lint passes
  • pnpm run build passes
  • pnpm run test:ci passes (911 tests, 55 new)
  • CHANGELOG.md updated under [Unreleased] (for user-facing changes)
  • Docs / README updated if behavior changed (docs/stability.md, docs/troubleshooting.md; README needed no change)
  • CLI ↔ MCP parity kept (no command or tool added; check:parity passes; qring doctor is CLI-only by the parity doc, so --fix has no MCP counterpart; emptyStored is surfaced on both list and list_secrets)

Verification

Run on Linux against a real passwordless GNOME keyring, with dummy keys and the keyring file backed up first:

  • the previous release wrote a value containing a double quote; it was empty seconds later, after the next keyring write, without a daemon restart (the bug);
  • the new build stored a multi-line value with a quote and a backslash, plus a quoted description, with no backslash in the stored line, and read it back identical before and after a daemon restart; the daemon logged no format error;
  • with two at-risk keys written by the previous release, doctor --fix converted the one that was still intact and reported the other as already empty; the converted key read back identical after a daemon restart;
  • get on the empty key printed the new error and exited 1, has exited 1, list marked the row; setting the key again worked.

An independent review of the first push found ten issues; eight are fixed in the later commits (read/write-back race, exec race, has/secretExists semantics, racy conversion advice, doctor ordering and wording, list surfacing, a redundant check).

Not covered, and known limits:

  • macOS Keychain and Windows Credential Manager: the write path is unchanged there, only the tests ran. KWallet, an encrypted GNOME keyring and the file backend were not run live.
  • export, exec and the MCP tools were verified by tests, not live.
  • The safe form is written on Linux only. Other platforms that use the Secret Service (the BSDs) keep plain JSON and are not protected.
  • The doctor scan cannot see other projects' scopes (keyed by a path hash) or team and org scopes; it says which scopes it covered.
  • validate --all, ci:validate, teleport pack and env generate fail on a key whose stored value is empty, naming it, where they used to treat it as an empty secret.

Breaking changes

None for stored data: existing entries are read as before.

Upgrade note: a q-ring older than this release does not know the safe form. It reads such an entry as a plain value (the wrapper text) and, because a read writes the entry back, rewrites it around that text and drops its metadata. Upgrade every q-ring install on a machine together and restart MCP servers that were already running.

qring has KEY and MCP has_secret now report a key whose stored value is empty as absent.

🤖 Generated with Claude Code

I4cTime and others added 9 commits November 14, 2026 13:25
The storage format gains a second, backslash-free form used on Linux when
the envelope JSON would contain an escape, and an empty stored string
becomes an error instead of a plain value. Documented before the code so
the format is decided in one place.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FkMFzKn8HJmUFi7uhH47Nf
…inux

A passwordless GNOME keyring is a plain text file that the daemon writes
raw and reads back with escape processing. An envelope whose JSON carried
an escape came back empty after a daemon restart, a newline escape made
the daemon reject the whole file, and q-ring then read the empty string
as a plain value and rewrote an empty envelope over it.

serializeEnvelope now wraps such an envelope as {v, enc: b64, data} on
Linux; parseEnvelope reads both forms everywhere. An empty stored string
is an EmptyStoredValueError on reads, a fresh start for set, still
deletable, marked in list and skipped with a warning by export and exec.
findStorageRisks reports keys still stored in the at-risk form.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FkMFzKn8HJmUFi7uhH47Nf
qring doctor tells a passwordless plain text GNOME keyring from an
encrypted one by the first bytes of the default keyring file and lists
keys that are still stored in the at-risk form or are already empty.
CLI set and MCP set_secret with env no longer fail on a key whose stored
value is empty, so a lost secret can be set again.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FkMFzKn8HJmUFi7uhH47Nf
The live test showed the value is lost when the daemon reloads its file,
which can be right after the next write, not only on restart.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FkMFzKn8HJmUFi7uhH47Nf
…st keys count as absent

Review of the PR showed three places where the format note was short of
what the code has to do: an older reader does not only misread a safe
form entry, it rewrites it; conversion needs one pass that does not race
the keyring daemon; and a lost key must not count as existing for
skip-existing checks. Amended before the code follows.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FkMFzKn8HJmUFi7uhH47Nf
…rom one snapshot

Review findings on the first pass. A passwordless GNOME keyring can drop
an at-risk entry on any keyring write, including q-ring's own, so:

- getSecret's write-back and the JIT re-read fall back to the envelope in
  hand when the stored copy has gone empty, which rewrites it safely;
- exec skips a key that goes empty between the list and its read;
- hasSecret and secretExists treat a lost value as absent, so
  import --skip-existing and lint --fix store the value again instead of
  skipping it (lint --fix removed the literal and kept nothing);
- convertStorageRisks rewrites every at-risk entry from a single snapshot
  without going through getSecret: no access count, no canary alert,
  expired entries included, one audit event per key;
- MCP exec names the keys it skipped; the redundant isSafeForm is gone.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FkMFzKn8HJmUFi7uhH47Nf
The storage check now runs before the backend probe (the probe writes to
the keyring), names the scopes it covers, and points to doctor --fix
instead of one qring get per key, which could drop the remaining keys.
qring list, list --json and MCP list_secrets mark a key whose stored
value is empty, and analyze leaves such keys out.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FkMFzKn8HJmUFi7uhH47Nf
…safe form

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FkMFzKn8HJmUFi7uhH47Nf
@I4cTime
I4cTime merged commit 93e16b7 into main Nov 14, 2026
9 checks passed
@I4cTime
I4cTime deleted the feat/keyring-safe-envelope branch November 14, 2026 20:18
I4cTime added a commit that referenced this pull request Nov 14, 2026
…ck (#169)

Patch release. Secrets, descriptions or tags containing quotes,
backslashes or newlines are no longer lost in a passwordless GNOME
keyring: such envelopes are stored in a backslash-free safe form on
Linux, an empty stored value is an error instead of a silently rewritten
empty secret, and lost keys are marked in list and list_secrets. qring
doctor gains a keyring storage format check and --fix (#168).

Versions set by release:prepare in package.json, server.json and the
Cursor and Claude plugin manifests; CHANGELOG [Unreleased] rolled into
[0.19.2] - 2026-11-14.

Claude-Session: https://claude.ai/code/session_01FkMFzKn8HJmUFi7uhH47Nf

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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.

1 participant