fix: trim the body before sealing instead of appending a newline

The body was right-trimmed and then given a trailing newline back, which is
reasonable for a mail body and fatal for a published twtxt record: smolboid
refuses a post whose text carries a line break, because a record is one line
of a feed.

Trimming belongs here, before the seal, so the signature covers exactly the
text the author meant. A receiver cannot do it — stripping is not invertible,
so it could no longer rebuild the signed bytes to verify them.
This commit is contained in:
randogoth 2026-10-14 22:08:55 +03:00
parent 3a03fab876
commit fcb54e2b40

View file

@ -950,8 +950,14 @@ async function sendMail(toText, subject, body, replyTo, anonymous) {
// first reply from them reaches our main tier.
const accepted = store.accepted(addr.short);
if (accepted?.active) fields.push(["Accept", b32encode(tokenFor(master, accepted.identity))]);
// Trimmed before the payload is signed, so the signature covers exactly the
// text the author meant. A trailing newline is not content — but it becomes
// content the moment it is signed, and nothing downstream can strip it
// without invalidating the signature. smolboid, for one, refuses a post
// whose text carries a line break, because a published record is one line
// of a feed.
const bodyBytes = utf8Bytes(buildFrontmatter(fields.filter(([, v]) => v),
body.replace(/\s+$/, "") + "\n"));
body.trim()));
const envelope = seal(me, recipient, bodyBytes);
// §5.8: our token for their mailbox, if they have given us one.
const held = store.tokenFrom(addr.short);