The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.
TypeScript budget-trackercollaborativedockeritinerarymcp-serveroffline-firstopen-sourceopenstreetmappacking-listpwareal-timeself-hostedselfhostedtraveltravel-apptravel-journaltravel-plannertripitwanderlog
fix(oauth): userinfo reports email_verified only for an address the account did not set itself
Maurice9975f9f80f96
diff --git a/server/src/db/repositories/OauthTokens.repository.ts b/server/src/db/repositories/OauthTokens.repository.tsindex 43a297b66..eac360f45 100644--- a/server/src/db/repositories/OauthTokens.repository.ts+++ b/server/src/db/repositories/OauthTokens.repository.ts@@ -41,6 +41,7 @@ export interface OauthTokenWithUserRow {username: string;email: string;role: string;+ email_self_asserted: number;}/** OA17 (`findChainRoot`'s upward-walk read). */@@ -268,6 +269,7 @@ export class OauthTokensRepository extends TrekRepository<OauthTokens> {'u.username','u.email','u.role',+ 'u.email_self_asserted',]).where({ 'ot.access_token_hash': hash }).execute<OauthTokenWithUserRow | undefined>('get', false);diff --git a/server/src/nest/oauth/oauth-public.controller.ts b/server/src/nest/oauth/oauth-public.controller.tsindex e10f22520..0ec1b2c1f 100644--- a/server/src/nest/oauth/oauth-public.controller.ts+++ b/server/src/nest/oauth/oauth-public.controller.ts@@ -220,7 +220,7 @@ export class OauthPublicController {res.json({sub: String(info.user.id),email: info.user.email,- email_verified: true,+ email_verified: info.emailVerified,preferred_username: info.user.username,});}diff --git a/server/src/nest/oauth/oauth.service.ts b/server/src/nest/oauth/oauth.service.tsindex f47413ea6..ef1a9148b 100644--- a/server/src/nest/oauth/oauth.service.ts+++ b/server/src/nest/oauth/oauth.service.ts@@ -73,6 +73,8 @@ function expiriesAsIso(row: { access_token_expires_at: string; refresh_token_expexport interface OAuthTokenInfo {user: User;+ /** False when the account typed its email in itself; nobody has confirmed that address. */+ emailVerified: boolean;scopes: string[];clientId: string;audience: string | null;@@ -450,6 +452,7 @@ export class OauthService {return {user: { id: row.user_id, username: row.username, email: row.email, role: row.role as 'admin' | 'user' },+ emailVerified: !row.email_self_asserted,scopes: decodeJson(OAUTH_TOKEN_SCOPES, row.scopes, `client ${row.client_id} user ${row.user_id}`),clientId: row.client_id,audience: row.audience ?? null,diff --git a/server/tests/unit/nest/oauth.controller.test.ts b/server/tests/unit/nest/oauth.controller.test.tsindex 005fae481..6c3e88036 100644--- a/server/tests/unit/nest/oauth.controller.test.ts+++ b/server/tests/unit/nest/oauth.controller.test.ts@@ -428,12 +428,29 @@ describe('OauthPublicController /userinfo + /revoke', () => {expect(r1.headers['WWW-Authenticate']).toBe('Bearer realm="TREK MCP"');const r2 = makeRes();await opc(- osvc({ getUserByAccessToken: vi.fn().mockReturnValue({ user: { id: 1, email: '[email protected]', username: 'u' } }) }),+ osvc({+ getUserByAccessToken: vi+ .fn()+ .mockReturnValue({ user: { id: 1, email: '[email protected]', username: 'u' }, emailVerified: true }),+ }),rl(),).userinfo('Bearer tok', r2);expect(r2.body).toEqual({ sub: '1', email: '[email protected]', email_verified: true, preferred_username: 'u' });});+ it('userinfo: an email the account typed in itself is not reported as verified', async () => {+ const res = makeRes();+ await opc(+ osvc({+ getUserByAccessToken: vi+ .fn()+ .mockReturnValue({ user: { id: 2, email: '[email protected]', username: 'v' }, emailVerified: false }),+ }),+ rl(),+ ).userinfo('Bearer tok', res);+ expect(res.body).toEqual({ sub: '2', email: '[email protected]', email_verified: false, preferred_username: 'v' });+ });+it('userinfo: 404 empty when MCP is disabled', async () => {const res = makeRes();await opc(osvc({ mcpEnabled: vi.fn().mockReturnValue(false) }), rl()).userinfo('Bearer tok', res);diff --git a/server/tests/unit/nest/oauth.service.test.ts b/server/tests/unit/nest/oauth.service.test.tsindex 36c50ebed..5f48d0e14 100644--- a/server/tests/unit/nest/oauth.service.test.ts+++ b/server/tests/unit/nest/oauth.service.test.ts@@ -954,6 +954,19 @@ describe('getUserByAccessToken — includes clientId (C2)', () => {expect(info).not.toBeNull();expect(info!.clientId).toBe(clientId);});++ it('reports the email as verified unless the account typed it in itself', async () => {+ const { user } = createUser(testDb);+ const created = await makeClient(user.id);+ const clientId = created.client!.client_id as string;++ const first = await issueTokens(clientId, user.id, ['trips:read']);+ expect((await getUserByAccessToken(first.access_token))!.emailVerified).toBe(true);++ await updateRows(t, Users, { id: user.id }, { email_self_asserted: 1 });+ const second = await issueTokens(clientId, user.id, ['trips:read']);+ expect((await getUserByAccessToken(second.access_token))!.emailVerified).toBe(false);+ });});// ---------------------------------------------------------------------------