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:
khannurien
2026-10-09 16:18:21 +00:00
parent 66e402bd91
commit 83dc44050e
26 changed files with 420 additions and 121 deletions

View File

@@ -31,7 +31,7 @@ import {
updateClientAvatar,
} from "./ws-service.ts";
import { replaceUploadedFile, validateImageUpload } from "../lib/upload.ts";
import { AVATARS_DIR } from "../config.ts";
import { AVATARS_DIR, FEDERATION } from "../config.ts";
import { hashPassword } from "../lib/password.ts";
import { linkAttachments } from "./attachment-service.ts";
@@ -187,14 +187,15 @@ export function getUserById(userId: string): User {
/**
* Returns the user's live role and their last password change, before which
* their tokens don't count, or undefined when the user is gone, or comes from
* an instance an admin blocked. `lib/auth.ts` checks every session and media
* token against it.
* another instance while an admin blocks it or the deployment turns sign-ins
* from other instances off (`FEDERATION.incoming`). `lib/auth.ts` checks
* every session and media token against it.
*/
export function getSessionState(
userId: string,
): { role: Role; tokensValidAfter: string | null } | undefined {
const row = db.prepare(
`SELECT u.role, u.tokens_valid_after, p.status AS peer_status
`SELECT u.role, u.tokens_valid_after, ui.issuer, p.status AS peer_status
FROM users u
LEFT JOIN user_identities ui ON ui.user_id = u.id
LEFT JOIN federation_peers p ON p.issuer = ui.issuer
@@ -203,10 +204,12 @@ export function getSessionState(
| {
role: Role;
tokens_valid_after: string | null;
issuer: string | null;
peer_status: string | null;
}
| undefined;
if (!row || row.peer_status === "blocked") return undefined;
if (row.issuer && !FEDERATION.incoming) return undefined;
return {
role: row.role,
tokensValidAfter: row.tokens_valid_after,