fix(feeds): keep subscribable calendars working under default-deny

The ICS feed routes are documented as public - the secret token in the URL
is the credential - but nothing in the code said so, and the guard this
release makes global is default-deny. Every calendar client subscribed to
/api/feed/trip/<token>.ics would have started getting 401 on upgrade, and
a calendar app that stops fetching just goes quiet.

The e2e suite asserted anonymous access the whole time. It booted
[DatabaseModule, RealtimeModule, FeedsModule], and the APP_GUARDs live in
AppModule, so it was asserting against an app that had no opinion on
anonymity. It boots the real guard stack now, and fails without the fix.

The boot ratchet could not have caught this either: it only looked at routes
carrying @Public(), and GlobalAuthGuard stands down for ANY declared chain -
so a chain of guards that refuse a caller but never resolve one answers
strangers, invisibly. Split the inventory in two and write that half down as
well. It turns up two routes nobody had listed: the passkey login ceremony,
which genuinely runs before a session exists.
This commit is contained in:
Maurice
2026-08-23 09:34:45 +02:00
committed by Maurice
parent d91eda690a
commit 3f8a7a1ea9
4 changed files with 104 additions and 11 deletions
+16 -1
View File
@@ -18,6 +18,7 @@ import cookieParser from 'cookie-parser';
import type { Server } from 'http';
import { DatabaseModule } from '../../src/nest/database/database.module';
import { Test } from '@nestjs/testing';
import { APP_GUARD } from '@nestjs/core';
import { seedUser, sessionCookie } from './harness';
const { db } = vi.hoisted(() => {
@@ -73,6 +74,9 @@ import { FeedsModule } from '../../src/nest/feeds/feeds.module';
import { CalendarService } from '../../src/nest/calendar/calendar.service';
import { RealtimeModule } from '../../src/nest/realtime/realtime.module';
import { TrekExceptionFilter } from '../../src/nest/common/trek-exception.filter';
import { AppConfigModule } from '../../src/nest/app-config/app-config.module';
import { GlobalAuthGuard } from '../../src/nest/auth/global-auth.guard';
import { MfaPolicyGuard } from '../../src/nest/auth/mfa-policy.guard';
const BASE = 'https://trek.example.test';
@@ -82,7 +86,18 @@ describe('Calendar-feed e2e (real auth guard + temp SQLite)', () => {
let prevAppUrl: string | undefined;
async function build() {
const moduleRef = await Test.createTestingModule({ imports: [DatabaseModule, RealtimeModule, FeedsModule] }).compile();
// The global guards decide whether a route answers a stranger, and they live
// in AppModule — a suite that pins 'anonymous feed → 200' has to boot them,
// or it proves nothing about the app that actually runs (a missing @Public()
// on the feed controller passed here while production 401'd every calendar
// client).
const moduleRef = await Test.createTestingModule({
imports: [AppConfigModule, DatabaseModule, RealtimeModule, FeedsModule],
providers: [
{ provide: APP_GUARD, useClass: GlobalAuthGuard },
{ provide: APP_GUARD, useClass: MfaPolicyGuard },
],
}).compile();
const nest = moduleRef.createNestApplication();
nest.use(cookieParser());
nest.useGlobalFilters(new TrekExceptionFilter());
+22 -2
View File
@@ -18,7 +18,12 @@ vi.mock('../../../src/db/database', async () => {
import { Test } from '@nestjs/testing';
import { AppModule } from '../../../src/nest/app.module';
import { DatabaseService } from '../../../src/nest/database/database.service';
import { collectRouteGuards, PUBLIC_ROUTE_ALLOW_LIST, validateRouteGuards } from '../../../src/nest/common/validate-route-guards';
import {
ANONYMOUS_GUARDED_ROUTE_ALLOW_LIST,
collectRouteGuards,
PUBLIC_ROUTE_ALLOW_LIST,
validateRouteGuards,
} from '../../../src/nest/common/validate-route-guards';
async function buildApp() {
const moduleRef = await Test.createTestingModule({ imports: [AppModule] })
@@ -70,8 +75,23 @@ describe('route guard inventory', () => {
const entries = collectRouteGuards(app);
// The inventory only lists routes that opted out of the default. Anything
// absent from it falls to GlobalAuthGuard, which is the safe direction.
expect(entries.every((e) => ['public', 'optional-auth', 'declared-guards'].includes(e.cover))).toBe(true);
const covers = ['public', 'optional-auth', 'declared-guards', 'declared-guards-anonymous'];
expect(entries.every((e) => covers.includes(e.cover))).toBe(true);
expect(entries.filter((e) => e.cover === 'public').length).toBe(PUBLIC_ROUTE_ALLOW_LIST.length);
expect(entries.filter((e) => e.cover === 'declared-guards-anonymous').map((e) => e.id))
.toEqual(ANONYMOUS_GUARDED_ROUTE_ALLOW_LIST);
} finally {
await app.close();
}
});
it('ROUTES-006: a guard chain that never authenticates fails the gate unless it is written down', async () => {
const app = await buildApp();
try {
expect(() => validateRouteGuards(app, PUBLIC_ROUTE_ALLOW_LIST, []))
.toThrow(ANONYMOUS_GUARDED_ROUTE_ALLOW_LIST[0]);
expect(() => validateRouteGuards(app, PUBLIC_ROUTE_ALLOW_LIST, [...ANONYMOUS_GUARDED_ROUTE_ALLOW_LIST, 'GhostController.anonymous']))
.toThrow('GhostController.anonymous');
} finally {
await app.close();
}