v4: federated sign-in closes the holes a review found — a callback link made from someone else's sign-in signed the visitor in to that account, a password reset left the user's sessions on other instances open, and events could be lost, reordered or delayed. FederatedSignIn keeps the sign-in's state in sessionStorage (utils/auth/federation.ts) and FederationCallback finishes only a sign-in this tab started. A password reset tells the instances the user signed in to, as a change does. The outbox delivers each instance's events in the order they were made, the first that fails holding back the rest, so a late older update no longer undoes a newer one, and delivers to every instance at once, so a dead one delays none of the others; an event queued during a run is sent by it.

Receiving, a home's keys that can't be fetched answer 502, which the sender retries, instead of 401, which it dropped; a bad update answers 400 rather than 502; a blocked instance's events answer 403; events are limited to a burst of 120 per instance, and a token naming an unknown key refetches the keys at most once a minute. An avatar must be on its issuer's origin, and its URL is versioned by its file's write time instead of updatedAt, so a profile edit no longer makes clients download it again. An instance that doesn't answer can be blocked, keeping its name, though not trusted.

303 backend tests and 703 frontend tests pass, the federation tests 8 times in a row, and deno check, tsc, eslint, doc:lint and i18n:compile --strict are clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
khannurien
2026-10-09 16:05:11 +00:00
parent c77e173767
commit 66e402bd91
19 changed files with 447 additions and 128 deletions

View File

@@ -65,12 +65,14 @@ export function listPeers(trustedOnly: boolean): FederationPeer[] {
/**
* Puts the instance `instance` names on the list of `status`, for `/manage`,
* and returns it. It must answer as a gerbeur instance, whose name is kept.
* Blocking one ends the sessions of its users here at once: their tokens stop
* counting by `getSessionState`, and this closes their sockets.
* and returns it. A trusted one must answer as a gerbeur instance, whose name
* is kept; a blocked one is blocked whether it answers or not, keeping the
* name it had. Blocking one ends the sessions of its users here at once:
* their tokens stop counting by `getSessionState`, and this closes their
* sockets.
*
* @throws {APIException} 400 when `instance` names no instance, or this one,
* 502 when it doesn't answer as a gerbeur instance.
* 502 when an instance to trust doesn't answer as a gerbeur instance.
*/
export async function setPeer(
instance: string,
@@ -81,17 +83,20 @@ export async function setPeer(
if (issuer === PUBLIC_URL) {
throw new APIException(400, "That is this instance");
}
let name: string;
let name: string | null = null;
try {
name = (await fetchMetadata(issuer)).gerbeur_site_name;
} catch (err) {
console.error(`[federation] ${issuer} can't be added:`, err);
throw new APIException(502, "That address doesn't answer as a gerbeur");
console.error(`[federation] ${issuer} doesn't answer:`, err);
if (status === "trusted") {
throw new APIException(502, "That address doesn't answer as a gerbeur");
}
}
db.prepare(
`INSERT INTO federation_peers (issuer, status, name, created_at)
VALUES (?, ?, ?, ?)
ON CONFLICT (issuer) DO UPDATE SET status = excluded.status, name = excluded.name;`,
ON CONFLICT (issuer) DO UPDATE SET status = excluded.status,
name = coalesce(excluded.name, name);`,
).run(issuer, status, name, new Date().toISOString());
if (status === "blocked") {