feat(demo): the shared demo account keeps its keys, account and language

Every visitor of a demo instance signs in as the same account, so one
visitor's API key, MCP token, OAuth client, passkey or new email address
became everybody's. These writes now answer 403 for the demo account through
refuseForDemoAccount in demo-write.ts: creating API keys, creating and
deleting MCP tokens, registering, rotating and deleting OAuth clients,
approving an app and ending a connected app, changing the name, address or
picture, and enrolling, renaming or deleting passkeys. Password, 2FA,
account deletion, sessions and the own AI connection were refused already.

The demo account's language is fixed to English: a single settings write of
the language answers unchanged, a bulk save drops it and keeps the rest. The
MCP settings tool is held back for the demo account by the tool gate, as
every write tool is. The admin of a demo instance and every real instance
are untouched.
This commit is contained in:
Maurice
2026-10-24 23:33:48 +02:00
parent ec486214f1
commit eae74c5605
9 changed files with 456 additions and 5 deletions
@@ -5,6 +5,7 @@ import { CurrentUser } from '../auth-core/current-user.decorator';
import { JwtAuthGuard } from '../auth-core/jwt-auth.guard';
import { MfaExempt } from '../auth-core/mfa-policy.guard';
import { setAuthCookie } from '../common/cookie';
import { DEMO_ACCOUNT_REFUSAL, refuseForDemoAccount } from '../common/demo-write';
import { RateLimitService } from '../common/rate-limit.service';
import { sessionClientFrom } from '../sessions/sessions.service';
import {
@@ -69,6 +70,9 @@ export class PasskeyController {
@HttpCode(200)
@UseGuards(PasskeyEnabledGuard, JwtAuthGuard)
async registerOptions(@CurrentUser() user: User, @Body() body: PasskeyRegisterOptionsDto, @Req() req: Request) {
// Every visitor shares the demo account: a passkey enrolled on it would be
// one stranger's key to everybody's demo.
refuseForDemoAccount(user, DEMO_ACCOUNT_REFUSAL.passkeys);
await this.limit('mfa', req, 5);
// The Origin header is only a pre-ceremony sanity input (see PasskeyService)
// — the RP ID itself is never derived from request headers.
@@ -81,6 +85,7 @@ export class PasskeyController {
@HttpCode(200)
@UseGuards(PasskeyEnabledGuard, JwtAuthGuard)
async registerVerify(@CurrentUser() user: User, @Body() body: PasskeyRegisterVerifyDto, @Req() req: Request) {
refuseForDemoAccount(user, DEMO_ACCOUNT_REFUSAL.passkeys);
const result = await this.passkeys.passkeyRegisterVerify(user.id, body);
await this.audit.writeAudit({ userId: user.id, action: 'user.passkey_register', ip: getClientIp(req) });
return { success: true, credential: result.credential };
@@ -142,6 +147,7 @@ export class PasskeyController {
@Patch('credentials/:id')
@UseGuards(JwtAuthGuard)
async rename(@CurrentUser() user: User, @Param('id') id: string, @Body() body: PasskeyRenameDto) {
refuseForDemoAccount(user, DEMO_ACCOUNT_REFUSAL.passkeys);
await this.passkeys.renamePasskey(user.id, id, body?.name);
return { success: true };
}
@@ -154,6 +160,7 @@ export class PasskeyController {
@Body() body: PasskeyDeleteDto,
@Req() req: Request,
) {
refuseForDemoAccount(user, DEMO_ACCOUNT_REFUSAL.passkeys);
await this.limit('login', req, 5);
await this.passkeys.deletePasskey(user.id, id, body?.password);
await this.audit.writeAudit({