Require share_manage for the two public credentials (#1883)

Both advisories are the same mistake: a route that hands out a bearer token
treated trip membership as authorisation. Membership lets someone read the trip
while they are signed in. It does not let them mint a URL that reads it without
an account, keeps working after they are removed, and can be rotated out from
under the owner's calendar subscriptions.

The calendar feed token now sits behind TripAccessGuard plus
@RequirePermission('share_manage'), the same shape the rest of the trip-scoped
controllers use, which also replaces a hand-written access check that GET never
called at all. GET is gated with the writes because it returns the credential
itself, not its status. The share link's GET does what its own POST and DELETE
already did, and what the invite link next door already does for exactly this
reason.

Two things had to come with it or the gate would have been decoration. The MCP
tool get_share_link read the same token on membership alone, so it would simply
have become the new way in. And feed_token rides along in every trip payload
because TRIP_SELECT reads t.*: any member could have read the value out of
GET /api/trips/:id, the summary tool or the plugin RPC. It is blanked once in
the select and stripped in the two places that select the row directly.

The three service writes take the acting user and scope their UPDATE to a trip
that user can reach. The guard decides who may manage the credential; this only
makes sure a caller arriving another way cannot write to an id it guessed.

Client side, "Subscribe to calendar" is now behind the same permission on
desktop and mobile. Without that a member would have kept an entry whose enable
button silently does nothing, because IcsSubscribeModal swallows every non-200.
The one-off ICS download stays where it is: that is a file they may already read.

Instances that want members to manage these links can lower share_manage to
trip_member in the admin panel, which the tests cover.
This commit is contained in:
Maurice
2026-08-11 11:15:32 +02:00
committed by GitHub
parent 073e55cbe4
commit 8c8cc2a727
19 changed files with 303 additions and 64 deletions
+52
View File
@@ -268,6 +268,58 @@ describe('Shared trip access', () => {
.send({});
expect(res.status).toBe(404);
});
it('SHARE-026 — a plain member cannot read the share token', async () => {
// Reading the link hands out the credential for the anonymous /api/shared
// page, which outlives the membership that was used to fetch it. Under the
// default policy share_manage stays with the owner.
const { user: owner } = createUser(testDb);
const { user: member } = createUser(testDb);
const trip = createTrip(testDb, owner.id);
addTripMember(testDb, trip.id, member.id);
await request(app).post(`/api/trips/${trip.id}/share-link`).set('Cookie', authCookie(owner.id)).send({});
const res = await request(app).get(`/api/trips/${trip.id}/share-link`).set('Cookie', authCookie(member.id));
expect(res.status).toBe(403);
expect(res.body).toEqual({ error: 'No permission' });
});
it('SHARE-027 — the owner still reads it, and a non-member still gets 404 rather than 403', async () => {
const { user: owner } = createUser(testDb);
const { user: stranger } = createUser(testDb);
const trip = createTrip(testDb, owner.id);
await request(app).post(`/api/trips/${trip.id}/share-link`).set('Cookie', authCookie(owner.id)).send({});
const mine = await request(app).get(`/api/trips/${trip.id}/share-link`).set('Cookie', authCookie(owner.id));
expect(mine.status).toBe(200);
expect(mine.body.token).toBeTruthy();
// 404, not 403: a stranger must not learn that the trip id exists.
const theirs = await request(app).get(`/api/trips/${trip.id}/share-link`).set('Cookie', authCookie(stranger.id));
expect(theirs.status).toBe(404);
});
it('SHARE-028 — a member may read it once the instance lowers share_manage to trip_member', async () => {
const { user: owner } = createUser(testDb);
const { user: member } = createUser(testDb);
const trip = createTrip(testDb, owner.id);
addTripMember(testDb, trip.id, member.id);
await request(app).post(`/api/trips/${trip.id}/share-link`).set('Cookie', authCookie(owner.id)).send({});
const { invalidatePermissionsCache } = await import('../../src/nest/permissions/permissions.bridge');
testDb.prepare("INSERT OR REPLACE INTO app_settings (key, value) VALUES ('perm_share_manage', 'trip_member')").run();
invalidatePermissionsCache();
try {
const res = await request(app).get(`/api/trips/${trip.id}/share-link`).set('Cookie', authCookie(member.id));
expect(res.status).toBe(200);
expect(res.body.token).toBeTruthy();
} finally {
// Module-scoped cache: leaving it set would decide the next file's tests.
testDb.prepare("DELETE FROM app_settings WHERE key = 'perm_share_manage'").run();
invalidatePermissionsCache();
}
});
});
describe('Shared trip — day assignments and notes', () => {
+18
View File
@@ -1032,6 +1032,24 @@ describe('ICS export', () => {
const res = await request(app).get(`/api/trips/${trip.id}/export.ics`);
expect(res.status).toBe(401);
});
it('TRIP-025b — the trip payload never carries feed_token, not even for the owner', async () => {
// feed_token is the sole credential for the anonymous ICS feed. TRIP_SELECT
// reads `t.*`, so without the blanking it ships in every trip response and
// gating /feed/token on share_manage would achieve nothing: any member
// could read the value straight out of GET /api/trips/:id.
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id, { title: 'Trip' });
testDb.prepare('UPDATE trips SET feed_token = ? WHERE id = ?').run('secret-feed-token', trip.id);
const one = await request(app).get(`/api/trips/${trip.id}`).set('Cookie', authCookie(user.id));
expect(one.status).toBe(200);
expect(one.body.trip.feed_token ?? null).toBeNull();
expect(JSON.stringify(one.body)).not.toContain('secret-feed-token');
const list = await request(app).get('/api/trips').set('Cookie', authCookie(user.id));
expect(JSON.stringify(list.body)).not.toContain('secret-feed-token');
});
});
// ─────────────────────────────────────────────────────────────────────────────