Skip to content

Hush's data folder is private, files from chats get Gatekeeper's check, and pasted pictures are cleaned up - #175

Merged
pitis merged 2 commits into
mainfrom
fix/files-locked-down
Nov 14, 2026
Merged

pitis merged 2 commits into
mainfrom
fix/files-locked-down

Conversation

@pitis

@pitis pitis commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

What changed

  • The data folder is private (0700) in both apps. The core's spawn (actor.rs) sets 0700 on the folder after creating it, so a new folder starts private and an existing one is tightened the next time it opens. Unix only; on Windows the per-user app data folder's ACL already keeps other users out. If the file system won't take a mode, the core logs a warning and still opens: refusing to open wouldn't make the folder private.
    • The files inside keep their modes (0644 from the umask). They don't need tightening: to open a path, another user needs search permission on every folder in it, and 0700 takes that away. No hard link to a stored file is left outside the folder for others to reach: the Mac app's opened-file links sit in the per-user $TMPDIR, and the desktop app makes none.
  • A file opened or exported from a chat is quarantined. Files.quarantine writes com.apple.quarantine with setxattr: 0081;<hex time>;Hush;. Those are the download flags Launch Services writes itself. Gatekeeper then checks a .command or .terminal a contact sent before it runs.
    • The mark has no event id. Going through URLResourceValues.quarantineProperties would also add a lasting row to ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV2 on every open, which is a record of when attachments were opened.
    • A file that is already marked keeps its mark, and with it any "Open Anyway" given before.
    • Files.openable (Quick Look, its Open With, and the audio player) quarantines the file it makes. That file is usually a hard link, and the mark lives on the inode, so the stored attachment gets it too. That does no harm: it's an attachment, not a database, and Hush only reads it. A later export also carries the mark over.
    • Export Chat quarantines everything in the export's files/ folder, off the main thread. chat.html stays unmarked: Hush writes it itself and it has no script in it. Marking is best effort: a file that can't be marked is logged, and the finished export is still returned and shown.
    • I chose this over LSFileQuarantineEnabled, which would quarantine every file Hush writes (the databases and backups too) and would be harder to test.
    • There is no drag-out or "Save as…" path for attachments. The backup NSSavePanel writes Hush's own encrypted file, which isn't a chat's file, so I left it alone.
  • Pasted pictures don't stay in $TMPDIR/Hush-paste. A pasted picture is deleted once its message is sent (the core has made its own copy by then), when it's taken out of the tray, or when switching chats empties the tray. A send that fails puts it back in the tray, and it stays. A failed send after the chat was switched deletes it. Files.clearLeftovers() (formerly clearOpened) empties both Hush-open and Hush-paste. It runs in AppStore.openReal once the core holds the data folder, so a second copy of Hush that is refused the folder can't clear the running copy's files. Only files directly in the paste folder are deleted (.. is resolved first). Files chosen or dropped from the user's own folders are never deleted.
  • Desktop app: it leaves no temporary files. It has no attach, paste, open or export path, and the core writes only inside the data folder (its temp_dir uses are all in tests).

Why

Closes #165. The folder was 0755 with 0644 files, so on Linux, where home folders are often 0755, other users could read the desktop app's attachments. Opened files had no quarantine mark, so a script a contact sent could run from Quick Look without a Gatekeeper check. Pasted pictures stayed in $TMPDIR until the system cleaned it.

How it was tested

Each test below was written first and failed before its fix:

  • Rust client::tests::the_data_folder_is_ours_alone: a new folder is 0700, and a 0755 folder is 0700 again after it opens. Before the fix the mode was 0755.
  • Swift FilesTests.testOpenedFilesAreQuarantined: the file openable makes carries the mark 0081;<8 hex digits>;Hush;, and a file already marked keeps its mark.
  • Swift AppStoreBackupTests.testAnExportReachesTheCoreAndAFailureIsShown: the fake core now writes an export like the real one. Its files/ entries are quarantined and chat.html is not. A file that can't be marked (a dangling link) is logged, and the export is still returned with no error shown.
  • Swift AppStoreFilesTests.testPastedPicturesGoOnceSentOrDropped: covers sent, failed (kept), removed from the tray, a .. path (kept), switching chats, a failed send after a chat switch (deleted), the user's own file (kept) and the clear-out. PasteTests now checks that a pasted picture is written to Files.pasteRoot. Every test that touches these folders swaps both of them (useTemporaryRoots), so none can reach the installed app's.
  • By hand:
    • A hard link and its original share the mark.
    • Running the tests that mark files adds no row to the quarantine events database (326 rows with agent Hush before and after, counted read-only).
    • libquarantine reads the direct mark as flags 0x81, agent Hush, and Launch Services reports it as quarantined.
    • spctl --assess --type open rejects an unsigned script with or without a mark, so it can't show the difference.
  • make format, make lint and cargo test -q (whole workspace) pass.
  • The full Swift suite was run unsigned, because this Mac has no signing certificate: 311 of 313 tests pass. The 2 that fail touch none of the code this PR changes:
    • LegacyTests.testSettingsAreAdoptedWithoutOverwritingNewOnes: persistentDomain returns [:], not nil, for a removed UserDefaults domain.
    • The on-screen MessageRowTests.testRightClickOnTextClickedIntoShowsTheMessageMenu. The on-screen TimelineOpenTests.testALongChatOpensWithOnePageAtItsNewestMessage failed in the first run and passed in the second.
    • I didn't rebuild main to confirm that they fail there too: disk space is short.

Not run in the real app: the owner's installed Hush was running, and its data folder was in use.

The data folder is 0700 in both apps (made so and tightened at open,
Unix only). A file opened from a chat or exported with it carries the
quarantine mark, so Gatekeeper checks it before it runs. Pasted
pictures are removed once sent or dropped from the tray, and what a
previous run left in Hush-paste goes at launch.
…the app's temp folders

The mark is written directly (Launch Services' download flags, no event
id), so opening an attachment leaves no row in the quarantine events
database, and a file already marked keeps its mark and any Open Anyway.
Exporting returns the finished folder even when a file can't be marked,
marking off the main thread. Pasted pictures go only from the paste
folder itself. Leftovers are cleared once the core holds the data
folder, so a refused second copy can't clear the running one's. Tests
swap both temp roots before clearing.
@pitis

pitis commented Nov 14, 2026

Copy link
Copy Markdown
Owner Author

Review findings and fixes (231df1e). There were no Critical findings.

Important

  1. Two tests deleted the installed app's temp folders. clearLeftovers reached the real Hush-open or Hush-paste in the per-user $TMPDIR.
    • Fixed: the new useTemporaryRoots(in:) swaps both roots and restores them on teardown.
    • It's used by every test that touches these folders: testStoredFilesOpenUnderTheirOwnName, testOpenedFilesAreQuarantined, testPastedPicturesGoOnceSentOrDropped, and PasteTests, which also wrote into the real Hush-paste.
    • testStoredFilesOpenUnderTheirOwnName now also checks that the clear-out leaves the test's own folder alone.
  2. An export was reported as failed when one file couldn't be marked.
    • Fixed: marking is best effort. Files.quarantineFiles(in:) marks as many files as it can and returns the failures; exportChat logs a count and the first error, then returns the finished folder, so Finder still opens.
    • Test: a dangling link in files/ is logged, the export is still returned, and no error is shown.

Suggestions

  1. Privacy: every mark added a row to the quarantine events database, and re-marking reset "Open Anyway".
    • Fixed: Files.quarantine writes the mark directly with setxattr as 0081;<hex time>;Hush;. Those are Launch Services' own download flags, with no event id. A file that is already marked is skipped.
    • Verified: the marking tests add no row (326 rows with agent Hush before and after, counted read-only with sqlite3). libquarantine reads the mark as flags 0x81, agent Hush, and Launch Services reports it as quarantined.
    • spctl --assess --type open --context context:primary-signature can't show the difference: it rejects an unsigned .command with or without a mark ("no usable signature"). So the check that Gatekeeper honours the mark rests on libquarantine and Launch Services reading it. The flags are byte for byte what the URL API wrote, so no fallback was needed.
    • The test now asserts the raw mark format, and that an existing (approved) mark is kept.
    • Note for the owner: the test runs before this fix, and one manual check, left about 24 rows with agent "Hush" in that database. A batch of 302 rows at 03:00:58 isn't from this branch's runs. I didn't touch the database.
  2. Files.discard didn't resolve ... Fixed: the path is standardized and its parent folder must be pasteRoot. Test: pasteRoot/../own.png is kept.
  3. clearLeftovers ran before the core's lock.
    • Fixed: it now runs in AppStore.openReal, right after Client.open succeeds. A second copy that gets AlreadyOpen clears nothing.
    • I put it there rather than in boot() because boot() also runs in tests with fake cores, which would bring back finding 1. openReal runs only in the real app.
    • The call in HushApp.init is gone.
  4. The catch branch that deletes after a chat switch had no test. Added: a failed send (with sendDelay and sendError) whose chat was switched away deletes the pasted picture. I checked that the test fails without that branch.
  5. Export marking ran on the main actor. Fixed: it runs in a Task.detached.

Ruling: Linux files inside an already-0755 folder stay 0644, because the folder's 0700 stops any new lookup. Tightening every file is the owner's call.

Checks: make format, make lint and cargo test -q pass. In the full unsigned Swift suite, 311 of 313 tests pass. The two failures are LegacyTests.testSettingsAreAdoptedWithoutOverwritingNewOnes (a UserDefaults domain comes back as [:] instead of nil) and the on-screen MessageRowTests.testRightClickOnTextClickedIntoShowsTheMessageMenu, and they touch no code in this PR.

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.

Files Hush keeps outside its databases are locked down

1 participant