termchat.app

One message deep enough to crash the app, and a day of less code: termchat.app 0.40.1 to 0.40.4

29 November 2026

On Sunday two reviews of termchat.app 0.40 came in. One looked for what a hostile contact, stranger, group member or relay can do. The other looked only for code that does not need to exist. Four releases went out the same day: 0.40.1 to 0.40.4. This is what they found, and a few things we learned on the way.

termchat.app has had no independent audit yet. The security pass is AI-assisted: Claude Fable 5.2 reads the source on request, and Codex ran the review for less code. A model can miss whole classes of bugs, so read this as “what was found”, not “what is safe”. The full report, with its proofs of concept, is in review-2026-11-29.

One message, sixteen thousand notes deep (0.40.1)

Notes to self (ADR-046) send a note to your other devices as a message that holds a message: Note { body }. The rule says one level only, never a note inside a note. The rule was checked, but only after the message had been decoded.

The decoder reads a nested value by calling itself once per level, as deep as the bytes say. A Note costs one byte a level, so the 16 KiB message size holds about 16 000 levels. Each level takes about 1.3 KB of stack in a release build. A 2 MiB thread runs out at about 1 600 levels, the 8 MiB main thread at about 6 500. When the stack runs out, Rust does not panic and cannot recover: the process is killed.

What made it bad:

  • Anyone who could reach you. A stranger with your public invite, any contact, any member of a group you are in. The plaintext is read before anything checks who sent it.
  • Again at every start. The message is acknowledged to the relay only after it is handled. The app died first, so the relay delivered it again at the next start, and the app died again. That lasts until the message expires on the relay, 14 days.
  • One member, every phone. In a group, one message stopped every device of every member.

Nothing was read or changed: it was denial of service only. But someone hit by it could not even open the app to block the sender.

The fix (ADR-046 amendment 4) refuses the nesting while decoding, not after. The body inside a Note or a Copy has a decoder of its own that refuses another Note or Copy before it starts on it. A message is then at most two levels deep, whatever its bytes say. The refusal is the same “malformed” as before, so nothing on the wire changed and older apps talk to newer ones as before. We looked at a depth counter for the whole decoder and dropped it: it is more code and one more limit to choose, when the protocol needs exactly two levels.

Why the fuzzers never saw it

The decoder has been fuzzed every night for weeks. The fuzzer never found this because it never made a message long enough. libFuzzer keeps inputs at 4 096 bytes unless told otherwise, and the decoder accepts only the exact padded sizes: 512 bytes, 4, 16 and 64 KiB. The two large sizes, where this bug lived, were never decoded at all.

Now the two message fuzzers take inputs up to 64 KiB and start from one valid message of each size. One more surprise: F-Droid’s build server refuses binary files in the source, and those seed messages are binary. The F-Droid recipe now deletes the seed folder before the scan, since the app build never reads it.

If your app keeps closing at start, update: once updated, the bad message decodes to an error and is acknowledged, and it is gone.

Introductions that answered by themselves (0.40.2)

When Alice introduces Bob to Carol (ADR-045), Carol is asked first. If Carol already knew Bob, her app answered “no” at once, with no tap from her. For a key she did not know, it stayed silent until she decided.

That difference was a question anyone could ask. A contact with a changed app could name any key and see whether Carol’s app answered: is this person in Carol’s contacts? Is this incognito identity (ADR-014) really Carol? One key per message, with no limit, because known keys did not count against the limit of five waiting introductions.

Now nothing goes back unless Carol taps something. A request for someone she already knows waits like any other, counts against the five, says “whom you already know” in her chat, and expires after seven days without an answer. Alice sees “waiting” either way. The same release keeps at most five passed-on invites per introducer, takes introductions and large documents only from a contact’s main device, as the design always said, and refuses a document in a group whose id another member already used.

A delete that could hit the wrong message (0.40.3)

The review for less code asked where the desktop, terminal and Android apps each do the same job in their own way. One answer turned out to be a bug in all three.

When you chose “Delete for both”, the confirmation remembered which row of the chat the message was on. If an older disappearing message above it ran out while the question was open, every row below moved up by one. Confirming then deleted the message next to yours, for both of you. The same happened to an edit, an answer or a forward that waited on you.

The fix gives a message a key that does not move: its id, its side and its time. The row is looked up only when the action runs. If the message has gone meanwhile, you get “the message is gone” instead of a wrong delete.

A smaller one in the same release: a test of the terminal daemon failed now and then under load. The test was right. The daemon’s socket briefly had the default rights before it was made private to its owner. It was never open to others, since the daemon checks who connects, but now the socket is made under another name, made private and only then moved into place.

Less code, one behaviour (0.40.3 and 0.40.4)

Less code is less to read, test and audit. The first review found 14 places in the Rust crates that could go or merge. Twelve are done, about 100 lines fewer: an unused function, a dependency the terminal app declared and never used, three copies of “make the record of a document we send”, two parsers of “30s, 5m, 1h”. Two were left on purpose: merging them would save 15 lines and risk mixing up which side of a chat a change came from, or the exit codes scripts rely on.

The second pass looked across the three apps. Three of them had their own Markdown formatting buttons: the engine counts text in bytes, the desktop in characters, Android in UTF-16 units, where one emoji is two. Now one function in the engine does it, and Android’s side converts its UTF-16 positions once, with tests that put emoji in the selection. Grouping of reactions, the warning when you leave a group, the mute and timer cycles and short times like “5m” now come from the engine too.

That pass saved almost no lines: shared code needs a bridge to each app, and the new tests take the rest. Its value is elsewhere. Two copies of the same rule drift apart, and these had: Android’s share screen called a 1 024-byte file 2 KB while its chat said 1 KB, Android said a public invite was renewed even when renewing failed, the desktop’s wipe dialog ignored a mistyped word without a word, and a search in Notes could leave an empty screen without “Nothing found”. Hunting for repeated code turned out to be a bug hunt.

What is still true

  • An update fixes these for you, not for a contact who has not updated: an older app still crashes on the nested message.
  • A contact still learns something from your own answer to an introduction. A “no” says you saw it. That is the answer you chose to give.
  • The relay still sees what the threat model says it sees.

Update to 0.40.4 from the download page, with Homebrew, or from the notice in the app. Everything since 0.40 is in the changelog.

Install termchat.app