File zone: a receipt counts only from @<mind>:<this homeserver>; doc says what info holds when media fails to load
Some checks failed
Build pull request / Build pull request (pull_request) Has been cancelled
Some checks failed
Build pull request / Build pull request (pull_request) Has been cancelled
Soul: a federated @void:evil.example passed the localpart check. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
c34e536132
commit
08ecacd438
4 changed files with 18 additions and 13 deletions
|
|
@ -24,11 +24,11 @@ A file event is an `m.room.message` whose `msgtype` is `m.audio`, `m.image`, `m.
|
|||
| `info.size` | content | bytes of the file as uploaded |
|
||||
| `info.sha256` | content | lower-case hex sha256 of the plaintext bytes, computed by the client before send; written in unencrypted rooms only (a plaintext hash in an encrypted room would leak the file's identity) |
|
||||
|
||||
The hash is computed over the same bytes that are uploaded. A file sent by something other than this
|
||||
The hash is computed over the same bytes that are uploaded, reading the whole file into memory before send (large videos pay for it); if hashing fails the file is sent without one. A file sent by something other than this
|
||||
client may lack `info.sha256`; the mouth then logs the hash it computed, and the row can show no `read by`
|
||||
for it.
|
||||
|
||||
Image and video events also carry `info.w`, `info.h`, `info.xyz.amorgan.blurhash` and a thumbnail
|
||||
`info.mimetype` and `info.size` are written on audio and file events always; on image and video events `info` exists only if the browser could load the media, otherwise `info` holds `sha256` alone. Image and video events also carry `info.w`, `info.h`, `info.xyz.amorgan.blurhash` and a thumbnail
|
||||
reference; audio carries no duration. A Mind should not rely on any of those.
|
||||
|
||||
## Limits and refusals
|
||||
|
|
@ -62,7 +62,7 @@ Two rules, both enforced on each side:
|
|||
|
||||
1. **The sender is the Mind.** The row trusts the Matrix `sender` of the receipt event and nothing inside it:
|
||||
no Mind field is read. `read by X` counts only when the sender is X's own Matrix identity (the
|
||||
localpart is a Mind in the Persona catalogue; a display name or a lookalike does not count).
|
||||
full id is `@<mind>:<this homeserver>` for a Mind in the Persona catalogue; a display name, a lookalike or another server's `@void:evil.example` does not count).
|
||||
2. **Read means verified.** The Mind posts only after the sha256 of the bytes it fetched equals the file
|
||||
event's `info.sha256`, and the receipt carries that hash. On a mismatch it posts nothing (or a typed
|
||||
refusal that the row does not draw). The row checks it again: the receipt's `sha256` must equal the
|
||||
|
|
|
|||
|
|
@ -235,6 +235,8 @@ describe('Mind receipts', () => {
|
|||
content: { 'org.gamecult.file_received': { event_id: fileId, sha256: sha, ...extra } },
|
||||
} as ZoneEvent);
|
||||
|
||||
const one = (r: ZoneEvent, replies: ZoneEvent[]) => buildAlbums([{ root: r, replies }], 'x')[0];
|
||||
|
||||
it('shows who read a file when the receipt carries the file event hash', () => {
|
||||
const a = one(root('$r', 1), [file('$f', HASH), receipt('$x', 20, '@void:x', '$f', HASH)]);
|
||||
expect(a.files[0].readBy).toEqual([{ sender: '@void:x', ts: 20 }]);
|
||||
|
|
@ -258,12 +260,14 @@ describe('Mind receipts', () => {
|
|||
]);
|
||||
expect(a.files[0].readBy).toEqual([]);
|
||||
});
|
||||
it('counts only a Mind identity: the localpart, not a display name or a lookalike server part', () => {
|
||||
it('counts only a Mind of this homeserver: not another server, a lookalike, or a bare name', () => {
|
||||
const a = one(root('$r', 1), [
|
||||
file('$f', HASH),
|
||||
receipt('$x', 20, '@void-fan:x', '$f', HASH),
|
||||
receipt('$y', 21, '@x:void', '$f', HASH),
|
||||
receipt('$z', 22, '@aqua:x', '$f', HASH),
|
||||
receipt('$e', 23, '@void:evil.example', '$f', HASH),
|
||||
receipt('$b', 24, 'void:x', '$f', HASH),
|
||||
]);
|
||||
expect(a.files[0].readBy.map((r) => r.sender)).toEqual(['@aqua:x']);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -98,15 +98,15 @@ const receiptOf = (e: ZoneEvent) => {
|
|||
};
|
||||
|
||||
// Only the event's sender counts, never a name inside the content, and only a Mind's own Matrix
|
||||
// identity (localpart in the Persona catalogue). "Read" means verified: the receipt's hash must be
|
||||
// identity on this homeserver (`@<mind>:<server>`, the mind named in the Persona catalogue). "Read" means verified: the receipt's hash must be
|
||||
// the file event's own.
|
||||
const isMind = (sender: string) => MINDS.includes(sender.replace(/^@/, '').split(':')[0]);
|
||||
const isMind = (sender: string, server: string) => MINDS.some((m) => sender === `@${m}:${server}`);
|
||||
|
||||
const attachReceipts = (files: AlbumFile[], replies: ZoneEvent[]) => {
|
||||
const attachReceipts = (files: AlbumFile[], replies: ZoneEvent[], server: string) => {
|
||||
const byId = new Map(files.map((f) => [f.id, f]));
|
||||
replies
|
||||
.map(receiptOf)
|
||||
.filter((r): r is NonNullable<typeof r> => !!r && isMind(r.sender))
|
||||
.filter((r): r is NonNullable<typeof r> => !!r && isMind(r.sender, server))
|
||||
.sort((a, b) => a.ts - b.ts)
|
||||
.forEach((r) => {
|
||||
const file = byId.get(r.file);
|
||||
|
|
@ -130,7 +130,7 @@ const titleOf = (root: ZoneEvent & { content: Record<string, unknown> }): string
|
|||
return asString(edited) || asString(root.content.body) || UNTITLED;
|
||||
};
|
||||
|
||||
const toAlbum = (input: AlbumInput): Album | undefined => {
|
||||
const toAlbum = (input: AlbumInput, server: string): Album | undefined => {
|
||||
const { root, replies } = input ?? {};
|
||||
if (!live(root)) return undefined;
|
||||
const seen = new Set<string>();
|
||||
|
|
@ -142,7 +142,7 @@ const toAlbum = (input: AlbumInput): Album | undefined => {
|
|||
return true;
|
||||
})
|
||||
.sort((a, b) => a.ts - b.ts);
|
||||
attachReceipts(files, Array.isArray(replies) ? replies : []);
|
||||
attachReceipts(files, Array.isArray(replies) ? replies : [], server);
|
||||
return {
|
||||
id: root.event_id,
|
||||
title: titleOf(root),
|
||||
|
|
@ -155,10 +155,11 @@ const toAlbum = (input: AlbumInput): Album | undefined => {
|
|||
};
|
||||
|
||||
/** Newest album first; files oldest first. Loose room messages never reach this function. */
|
||||
export const buildAlbums = (inputs: AlbumInput[]): Album[] => {
|
||||
/** `server` is the homeserver's own domain: only its Minds' receipts count. */
|
||||
export const buildAlbums = (inputs: AlbumInput[], server = ''): Album[] => {
|
||||
const seen = new Set<string>();
|
||||
return inputs
|
||||
.map(toAlbum)
|
||||
.map((i) => toAlbum(i, server))
|
||||
.filter((a): a is Album => {
|
||||
if (!a || seen.has(a.id)) return false;
|
||||
seen.add(a.id);
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ export const useAlbums = (room: Room): AlbumsState => {
|
|||
)
|
||||
).chunk ?? [],
|
||||
}));
|
||||
return buildAlbums(inputs);
|
||||
return buildAlbums(inputs, mx.getDomain() ?? '');
|
||||
},
|
||||
retry: 1,
|
||||
refetchInterval: REFRESH_MS,
|
||||
|
|
|
|||
Loading…
Reference in a new issue