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:
@@ -14,6 +14,7 @@ import {
|
||||
test,
|
||||
} from "../helpers.ts";
|
||||
import { assert, assertEquals, assertMatch } from "@std/assert";
|
||||
import { clearInstanceCaches } from "../../remote/gerbeur-instance.ts";
|
||||
import type {
|
||||
FederationLoginResponse,
|
||||
FederationPeer,
|
||||
@@ -265,6 +266,64 @@ test("federation: the home's events rename, update and sign out its users", asyn
|
||||
assertEquals((await get("/api/me", { auth })).status, 401);
|
||||
});
|
||||
|
||||
test("federation: a home's events are refused from a blocked home, with an avatar elsewhere, and put off when its keys fail", async () => {
|
||||
const home = await fakeInstance(HOME);
|
||||
let keysDown = false;
|
||||
using net = stubNetwork((url, init) =>
|
||||
keysDown && url.pathname === "/.well-known/jwks.json"
|
||||
? new Response("", { status: 503 })
|
||||
: home.handle(url, init) ?? new Response("", { status: 404 })
|
||||
);
|
||||
await trust(HOME);
|
||||
await signIn(home, ALICE);
|
||||
const send = async (payload: Record<string, unknown>) =>
|
||||
(await post("/api/federation/events", {
|
||||
json: { event: await home.event(ALICE.sub, payload) },
|
||||
})).status;
|
||||
|
||||
// Answered 5xx, so that the home tries again rather than give up.
|
||||
keysDown = true;
|
||||
clearInstanceCaches();
|
||||
assertEquals(await send({ type: "revoke" }), 502);
|
||||
keysDown = false;
|
||||
|
||||
const avatars = net.calls.filter((u) => u.pathname.endsWith("/avatar"))
|
||||
.length;
|
||||
assertEquals(
|
||||
await send({
|
||||
type: "update",
|
||||
claims: { ...ALICE, picture: "https://elsewhere.test/a.png" },
|
||||
}),
|
||||
400,
|
||||
);
|
||||
assertEquals(
|
||||
net.calls.filter((u) => u.pathname.endsWith("/avatar")).length,
|
||||
avatars,
|
||||
);
|
||||
|
||||
await trust(HOME, "blocked");
|
||||
assertEquals(
|
||||
await send({
|
||||
type: "update",
|
||||
claims: { ...ALICE, preferred_username: "mallory" },
|
||||
}),
|
||||
403,
|
||||
);
|
||||
assertEquals(
|
||||
(await get<SelfUser>("/api/users/@alice@home.test")).data.username,
|
||||
"alice@home.test",
|
||||
);
|
||||
});
|
||||
|
||||
test("federation: an instance that doesn't answer can be blocked, not trusted", async () => {
|
||||
using _net = network();
|
||||
assertEquals((await trust("https://down.test")).status, 502);
|
||||
const blocked = await trust("https://down.test", "blocked");
|
||||
assertEquals(blocked.status, 200);
|
||||
assertEquals(blocked.data.status, "blocked");
|
||||
assertEquals(blocked.data.name, null);
|
||||
});
|
||||
|
||||
test("federation: an account from another instance changes its password, email, avatar and name there", async () => {
|
||||
const home = await fakeInstance(HOME);
|
||||
using _net = network(home);
|
||||
|
||||
Reference in New Issue
Block a user