fix(public-api): a key narrowed away from days stops getting days back through places

Places, notes and reservations hang off days, so asking for one of them implies
the day container. That implication ran ahead of the grant: a key minted with
scopes ['trips','places'] and deliberately no 'days' still received every day's
title and the day's own free-text notes, either by naming places or by naming
nothing at all, since an absent include narrows to the granted sections and
lands back in the same branch. Asking for days by name was a 403 the whole
time, so the two routes disagreed about the same fields.

The grant now reaches the service alongside the narrowed include. The container
is still implied, because the places inside it are useless without their date,
but the day's title and notes only go out to a key that was granted days. A key
with full access is unaffected: it is granted days whether or not it asks.
This commit is contained in:
Maurice
2026-09-13 22:27:01 +02:00
parent 54e5525568
commit c42cf5477b
5 changed files with 58 additions and 16 deletions
@@ -12,6 +12,7 @@ import { ApiTokenGuard } from './api-token.guard';
import { PublicApiService } from './public-api.service';
import {
enforcePublicApiRateLimit,
grantedScopes,
narrowToGrant,
requireScope,
requireUserId,
@@ -98,7 +99,10 @@ export class PublicApiController {
}
const allowed = narrowToGrant(asked, req);
const trip = this.api.getTrip(tripId, requireUserId(req), allowed);
// The grant goes in as well as the narrowed include: days are implied by any
// section that hangs off them, and the implied block must still be measured
// against what the key may read.
const trip = this.api.getTrip(tripId, requireUserId(req), allowed, grantedScopes(req));
if (!trip) {
throw new HttpException({ error: 'Trip not found' }, 404);
}