v4: a deployment chooses which ways federated sign-in goes — every instance took users of the others and let its own sign in to them, with no way to turn either off. GERBEUR_FEDERATION_INCOMING=0 keeps users of other instances out: the login and register pages offer no other instance, /manage no list of instances, their sign-ins are refused, and those already in are signed out until it is on again, their homes' events still applied meanwhile. GERBEUR_FEDERATION_OUTGOING=0 keeps the instance's users from signing in elsewhere: its /authorize page lets no instance sign them in, its metadata says so (gerbeur_outgoing), which other instances check before sending anyone there, the settings page lists no instances, and at startup every grant is withdrawn, which signs them out there. Both are on by default and reach the client through index.html. The dev instance gerbeur (:3000) takes no users of the others, while its own still sign in to them.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -19,6 +19,7 @@ import { canonicalizeUrl } from "../lib/canonical-url.ts";
|
||||
import { clearRichContentCache } from "../services/rich-content-service.ts";
|
||||
import { clearImageCache } from "../remote/image-proxy.ts";
|
||||
import { clearInstanceCaches } from "../remote/gerbeur-instance.ts";
|
||||
import { FEDERATION } from "../config.ts";
|
||||
import {
|
||||
type OutgoingEmail,
|
||||
setEmailTransport,
|
||||
@@ -464,8 +465,14 @@ export interface FakeInstance {
|
||||
handle(url: URL, init?: RequestInit): Promise<Response> | null;
|
||||
}
|
||||
|
||||
/** Makes a {@link FakeInstance} at `origin` with a fresh key. */
|
||||
export async function fakeInstance(origin: string): Promise<FakeInstance> {
|
||||
/**
|
||||
* Makes a {@link FakeInstance} at `origin` with a fresh key, its metadata
|
||||
* with `metadata` over the defaults.
|
||||
*/
|
||||
export async function fakeInstance(
|
||||
origin: string,
|
||||
metadata: Record<string, unknown> = {},
|
||||
): Promise<FakeInstance> {
|
||||
const { kid, privateJwk, publicJwk } = await generateInstanceKey();
|
||||
const key = await importInstanceKey(kid, privateJwk);
|
||||
const codes = new Map<
|
||||
@@ -496,6 +503,7 @@ export async function fakeInstance(origin: string): Promise<FakeInstance> {
|
||||
gerbeur_site_name: `Fake ${new URL(origin).host}`,
|
||||
gerbeur_redirect_uri: `${origin}/federation/callback`,
|
||||
gerbeur_events_endpoint: `${origin}/api/federation/events`,
|
||||
...metadata,
|
||||
});
|
||||
case "/.well-known/jwks.json":
|
||||
return json({ keys: [publicJwk] });
|
||||
@@ -564,6 +572,20 @@ export async function fakeInstance(origin: string): Promise<FakeInstance> {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns one way of federated sign-in off for the life of the returned handle
|
||||
* (`using _off = federationOff("incoming")`), as `GERBEUR_FEDERATION_*=0`
|
||||
* would for the server's life.
|
||||
*/
|
||||
export function federationOff(way: keyof typeof FEDERATION): Disposable {
|
||||
FEDERATION[way] = false;
|
||||
return {
|
||||
[Symbol.dispose]() {
|
||||
FEDERATION[way] = true;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// ── Email ────────────────────────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user