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:
parent
3a03fab876
commit
fcb54e2b40
1 changed files with 7 additions and 1 deletions
|
|
@ -950,8 +950,14 @@ async function sendMail(toText, subject, body, replyTo, anonymous) {
|
||||||
// first reply from them reaches our main tier.
|
// first reply from them reaches our main tier.
|
||||||
const accepted = store.accepted(addr.short);
|
const accepted = store.accepted(addr.short);
|
||||||
if (accepted?.active) fields.push(["Accept", b32encode(tokenFor(master, accepted.identity))]);
|
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),
|
const bodyBytes = utf8Bytes(buildFrontmatter(fields.filter(([, v]) => v),
|
||||||
body.replace(/\s+$/, "") + "\n"));
|
body.trim()));
|
||||||
const envelope = seal(me, recipient, bodyBytes);
|
const envelope = seal(me, recipient, bodyBytes);
|
||||||
// §5.8: our token for their mailbox, if they have given us one.
|
// §5.8: our token for their mailbox, if they have given us one.
|
||||||
const held = store.tokenFrom(addr.short);
|
const held = store.tokenFrom(addr.short);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue