Skip to content

Group keys and contact ids stay out of logs, file names, notifications and preferences - #176

Merged
pitis merged 5 commits into
mainfrom
fix/keys-out-of-logs
Nov 14, 2026
Merged

pitis merged 5 commits into
mainfrom
fix/keys-out-of-logs

Conversation

@pitis

@pitis pitis commented Nov 14, 2026

Copy link
Copy Markdown
Owner

What changed

A group's chat id is g:<hex master key> and a 1:1 chat's is c:<ACI>. Both reached places outside the encrypted databases. Now:

  • Opaque ids. The core keeps a random per-install key in projection.db (new table install_key, migration 0029). ProjectionDb::opaque_id / Client.opaqueId is HMAC-SHA256 of an id under that key, truncated to 8 bytes (16 hex characters). Without the database, nobody can reverse it or test it against a known ACI. It uses the hmac/sha2 crates already in the tree.
  • Logs.
    • The core's own log lines name chats by opaque id (chat pictures, call messages, typing) or carry no id at all (decryption failures, retry receipts, read receipts, calls from unknown devices or unaccepted chats, duplicates). Two send-failure messages no longer embed the chat id.
    • Every log line, including presage's and libsignal's messages and errors (e.g. "session with <aci>.1 not found", presage's Thread(contact=…), trusting new identity with an address), goes through a Scrub layer in logging.rs. It blanks out UUIDs, hex runs of 32+ characters (keys), + phone numbers and decimal byte dumps.
    • libsignal_service::cipher is filtered to errors only, so its envelope-dumping warnings are gone. Its error lines stay, scrubbed.
    • The Swift side already logs core errors as .private. Nothing there needed changing.
  • Chat-picture files are now avatar-<opaque id>-<time>. At startup, rename_avatars (which replaces reroot_avatars and still handles a moved data folder) renames existing avatar-g-<key>-… / avatar-c-<aci>-… files and updates their rows. It renames first and updates the row second, so an interrupted run is finished by the next one. A picture whose file is gone is fetched again.
  • Notifications.
    • Ids, threadIdentifier and userInfo carry only opaque ids. A message's id is <opaque author>|<sentAt>|…, a reaction's adds <opaque reactor>|<emoji>, and calls use call|<opaque chat>.
    • A click, Reply or Mark as Read maps the opaque id back to the chat through the chat list.
    • Notifications left by older versions (named by chat id and ACI) are removed when the app starts.
  • Drafts move from UserDefaults (plain text that outlived disappearing timers, unlinking and the chat itself) into projection.db:
    • Table drafts, with Client.setDraft (blank text clears) and Client.drafts.
    • The app keeps an unobserved in-memory copy for the composer and chat list. Writes go to the core one after another.
    • At launch, draft.* keys in the preferences move into the core and are removed once stored. One that fails stays for the next launch.
    • A chat's draft goes when the chat is deleted (here or from the phone). Deleting waits for a draft write still on its way.
    • No other UserDefaults key holds a chat id (checked: appearance, notification content, menu bar, and window/panel state).

Backups and exports: drafts live in projection.db, so they are in backups like messages and are restored with them. They are not in chat exports, which hold the messages only. The install key is backed up too, so restored chat-picture names stay valid.

Desktop app: it keeps drafts in memory only and logs no ids. It shares the core's logging, so it gets the scrubbing too.

Why

With a master key and the group's encrypted state, anyone can read the group's title, members and picture. The unified log (as public text), file names, preferences and Notification Center's database all kept keys and ACIs, plus a timestamped record of who wrote when.

Closes #164

How it was tested

  • Test-first. Each new test failed before its fix: the scrub test fails with scrubbing off, and the draft-race test fails without the ordering. The rest failed to compile against the old API.
  • Rust: cargo test -p sig-core passes: 501 passed, 3 ignored. New tests:
    • the log scrub (a capturing layer behind Scrub: no ACI, PNI, key, phone number or byte dump gets through; error kinds, timestamps and opaque ids stay)
    • opaque ids are stable across reopening, differ between chats and between installs
    • picture files are named by opaque id
    • the rename migration covers keyed names, a moved folder, an interrupted rename, a missing file, and running a second time
    • drafts: set, replace, clear when blank, removed with the chat
  • make lint is clean (rustfmt, clippy -D warnings on all targets including core/desktop, swift-format strict).
  • Swift (unsigned, no certificate on this Mac): 314 tests, 2 failures, the same two that fail on origin/main in a full run here: LegacyTests.testSettingsAreAdoptedWithoutOverwritingNewOnes and the on-screen testRightClickOnTextClickedIntoShowsTheMessageMenu. New tests:
    • drafts are kept by the core
    • a draft write in flight doesn't bring a deleted chat's draft back
    • preference drafts move into the core (scratch UserDefaults suite) and leave the preferences; a failed one stays
    • notifications name no chat or person and still open their chat
    • old-format notifications are cleared
    • updated id, prefix and call-ring tests
  • Not run: the real app. The owner's installed Hush was running and holds the data folder, so the migration hasn't been seen on real data. make desktop (a full GPUI build) wasn't run for disk space. Clippy type-checks it.

…s and preferences

Chats get an opaque id: an HMAC of the chat id with a random key kept in
projection.db. Logs, chat-picture file names and notification ids, threads
and userInfo use it; every log line is scrubbed of service ids, phone
numbers, keys and byte dumps, and libsignal-service's envelope-dumping
decryption warnings are filtered out. Drafts move from UserDefaults into
projection.db and go with their chat. Existing chat pictures are renamed at
startup, safely across interruptions.
…hat's notifications and draft go, every log line and span is scrubbed and correlatable

Drafts: every change is written and a failed write is shown; nothing is
written until the drafts are read; they are read again after chat list
changes; a chat's draft leaves the app only once the core deleted it;
quitting waits for the last write; the move from the preferences keeps the
core's copy and drops drafts of chats that aren't listed.

Notifications: deleting a chat removes them; a click, reply or mark read
naming a chat that's gone logs it, a click still brings Hush up, and a reply
says the chat is gone; one constant for the userInfo key.

Logs: libsignal-service's cipher warnings are back, scrubbed; span fields
and byte fields are scrubbed too; decryption, retry, duplicate, unaccepted
call and read receipt lines carry the chat's opaque id, and error texts name
chats by it; sticker packs are named by a short tag.

Chat pictures: a picture that can't be renamed is left for the next start
and the others go on; missing ones are counted; files named by a chat that
no chat points to are removed.
@pitis

pitis commented Nov 14, 2026

Copy link
Copy Markdown
Owner Author

Review fixes, in c0935ca (after merging origin/main, which had #175's conflict in HushApp.swift). Each finding below is listed with its fix or ruling.

Important

  1. Drafts could be lost silently.
    • Every change is now written: the != kept guard is gone, so the next change retries a failed write. A failure goes to showError, which logs it with .private and shows it.
    • Nothing is written until drafts() has been read (draftsLoaded). If that read fails at launch, the app says so ("What you type isn't kept as a draft").
    • Tests: testAFailedDraftWriteIsShownAndTheNextChangeTriesAgain, testDraftsThatCouldntBeReadAreNotOverwritten.
  2. A draft of a chat deleted from the phone stayed in memory.
    • On .ready/.conversationsChanged, drafts are read again, queued after any writes still on their way. The result is dropped if something was typed meanwhile (draftEdits).
    • deleteChat now clears the in-memory draft only after the core's delete succeeds.
    • Tests: testADraftGoneWithItsChatOnThePhoneLeavesTheApp, testADraftStaysWhenItsChatCouldntBeDeleted. The ordering test was updated.
  3. Notification actions on an id that no longer maps to a chat.
    • deleteChat now removes the chat's notifications.
    • Mark as Read on such an id logs it.
    • A click on one still brings Hush up (defer { NSApp?.activate() }) and logs.
    • A reply to one logs, and the fallback notification says "Its chat is no longer in Hush." instead of telling the user to open it.
    • A tap on an old-format notification logs (SystemNotifier.logger).
    • post and the delegate now share one Notifications.chatKey constant for the userInfo key.
    • Tests: testANotificationWhoseChatIsGoneOpensNothingAndSendsNothing, plus an assertion in testANotificationNamesNoChatOrPersonButOpensItsChat that deleting a chat removes its notifications.
  4. libsignal_service::cipher=error hid the record of messages libsignal-service drops. The directive is removed; Scrub de-identifies those lines. The scrub test now logs a real proto::Envelope (string and binary source ids, a server GUID, content bytes). Its timestamp stays and every id is blanked.
  5. rename_avatars stopped at the first file error.
    • Each row is handled on its own. A failed rename logs chat = <opaque>, "a chat picture couldn't be renamed", leaves the row as it is and goes on; the next start retries it.
    • It now returns (moved, missing), and the actor's info line logs both.
    • Files named avatar-c-*/avatar-g-* that no row points to are removed. Such names never occur for new files, so after the first pass this only lists the folder.
    • The test now covers a rename blocked by something in the way (the others go on, and the next start finishes it), an orphaned keyed file removed, and an attachment file kept.
  6. Lines that lost their id couldn't be correlated.
    • These lines now carry chat = <opaque>: decryption, retry receipt, duplicate, unaccepted call, read receipt.
    • Error texts now name chats by opaque id instead of the chat id or sender: call message, session reset (both), storing a message, a message that may not have been sent, the disappearing timer, reaction/edit/delete, recording a change, no such chat, not a 1:1 chat with a known contact.
    • "The timer can be set here in direct chats only" no longer carries an id.
  7. Sticker pack ids were blanked in sig-core's own warnings. These lines now log pack_tag, the first 4 bytes of the pack id as hex (8 characters, under the 32-hex rule), in stickers.rs and in three places in actor.rs. The scrub test checks that the tag survives.
  8. Specs. native-glass-design: the unified log keeps the chat's opaque id, never the sender's ACI. block-requests-design: the delete_chat row lists the draft.

Suggestions taken

  1. stop() waits for the last draft write before stopping the core.
  2. The migration from the preferences reads drafts() first. A key whose chat already has a draft in the core is only removed, and a key whose chat isn't listed is removed without moving. The migration test covers both.
  3. Scrub now has record_bytes, which hex-encodes so the 32-hex rule applies. Span fields are scrubbed too (on_new_span, on_record). The test checks a span field and a byte field.
  4. The rename test asserts against the whole key ("ab".repeat(32)) instead of "abab".
  5. The draft tests remove their scratch suites (removePersistentDomain).
  6. opaque() returns an optional. Without a core, nothing is posted or removed. The ring removal is shared in removeRing.

Declined

  • Base64 and non-E.164 phone patterns in the scrub. No known log line prints them. This is written down as a known limit on scrub in logging.rs.
  • A real-app run of the migrations. It isn't possible while the owner's Hush is running: it holds the data folder, and there is no data-folder override. The unit tests cover the migrations; it's flagged for the owner.

Checks

  • Each new test was seen failing against the pre-review code (Swift: the old AppStore/Notifications; Rust: span scrubbing removed).
  • cargo test -p sig-core: 502 passed, 3 ignored.
  • make lint: clean, including clippy on core/desktop.
  • Unsigned Swift: 321 tests, with the same 2 failures as origin/main here (LegacyTests.testSettingsAreAdoptedWithoutOverwritingNewOnes, and the on-screen right-click menu test).
  • No real-app run: the owner's Hush is running.

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.

Group keys and contact ids stay out of logs, file names, notifications and preferences

1 participant