mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 15:17:30 +00:00
fix(api): read body, query and handler-parsed ids with toRowId instead of Number() and parseInt
The services and controllers that took an id from a request with Number(), parseInt() or not at all now use toRowId. That covers admin users, notifications (and their limit and offset), trip members and guests, day notes, assignments, memories (photo owner, album link, body photo_id), photos, mail-ingest, the assistant id parsers, dawarich, registration invites, the plugin contribution routes and the collab reply. The accommodation update body is open, so AccommodationsService reads the place and day refs of every stay write with toRowId and answers a refused one with the create schema's 400. AdminService.deleteUser checked the caller with parseInt and deleted with Number(), so an admin could delete their own account by spelling its id in hex; both now use one parse. The OAuth session revoke called Number(id) first and so revoked session 5 for '0x5'; the service now reads the id as sent.
This commit is contained in:
@@ -12,6 +12,7 @@ import { OauthService } from '../../src/nest/oauth/oauth.service';
|
||||
import { authCookie } from '../helpers/auth';
|
||||
import { updateRows, upsertRow } from '../helpers/factories/rows';
|
||||
import { makeUser } from '../helpers/factories/users';
|
||||
import { oneByOne } from '../helpers/one-by-one';
|
||||
import { resetDatabase } from '../helpers/reset-database';
|
||||
import { resetRateLimits } from '../helpers/test-db';
|
||||
import { MikroORM } from '@mikro-orm/core';
|
||||
@@ -1100,6 +1101,42 @@ describe('Sessions — /api/oauth/sessions', () => {
|
||||
expect(res.body).toEqual({ error: 'Session not found' });
|
||||
});
|
||||
|
||||
it('OAUTH-043C: DELETE /sessions/:id by a hex or exponent spelling of a real session id is 404 and revokes nothing', async () => {
|
||||
const { user } = await makeUser(orm);
|
||||
const { client } = await createOAuthClient(user.id, 'App', ['https://app.example.com/cb'], ['trips:read']);
|
||||
if (!client) throw new Error('the OAuth client was not created');
|
||||
const { verifier, challenge } = makePkce();
|
||||
const code = await createAuthCode({
|
||||
clientId: client.client_id as string,
|
||||
userId: user.id,
|
||||
redirectUri: 'https://app.example.com/cb',
|
||||
scopes: ['trips:read'],
|
||||
codeChallenge: challenge,
|
||||
codeChallengeMethod: 'S256',
|
||||
resource: null,
|
||||
});
|
||||
await request(app).post('/oauth/token').send({
|
||||
grant_type: 'authorization_code',
|
||||
client_id: client.client_id,
|
||||
client_secret: client.client_secret,
|
||||
code,
|
||||
redirect_uri: 'https://app.example.com/cb',
|
||||
code_verifier: verifier,
|
||||
});
|
||||
const sessionId = (await request(app).get('/api/oauth/sessions').set('Cookie', authCookie(user.id))).body
|
||||
.sessions[0].id as number;
|
||||
|
||||
// Number() read both as the session itself, so this route revoked it where every other answers 404.
|
||||
const spellings = [`0x${sessionId.toString(16)}`, `${sessionId}e0`];
|
||||
const answers = await oneByOne(spellings, async (spelling) => {
|
||||
const res = await request(app).delete(`/api/oauth/sessions/${spelling}`).set('Cookie', authCookie(user.id));
|
||||
return [res.status, res.body as unknown];
|
||||
});
|
||||
expect(answers).toEqual(spellings.map(() => [404, { error: 'Session not found' }]));
|
||||
const after = await request(app).get('/api/oauth/sessions').set('Cookie', authCookie(user.id));
|
||||
expect(after.body.sessions).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('OAUTH-044 — DELETE /sessions/:id returns 403 when addon disabled', async () => {
|
||||
await setMcpEnabled(false);
|
||||
const { user } = await makeUser(orm);
|
||||
|
||||
Reference in New Issue
Block a user