Skip to content

Commit 2e3491d

Browse files
authored
Merge pull request #10676 from simstudioai/codex/auth-session-logging-release
fix(auth): release grant revocation and safe email fallback logs
2 parents 62b6433 + df66528 commit 2e3491d

3 files changed

Lines changed: 112 additions & 15 deletions

File tree

‎apps/sim/lib/auth/auth.ts‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,16 @@ export const auth = betterAuth({
12701270
}
12711271
}),
12721272
after: createAuthMiddleware(async (ctx) => {
1273+
if (
1274+
ctx.path === '/change-password' &&
1275+
ctx.body?.revokeOtherSessions === true &&
1276+
isRecordLike(ctx.context.returned) &&
1277+
typeof ctx.context.returned.token === 'string' &&
1278+
ctx.context.newSession?.user.id
1279+
) {
1280+
await revokeUserOAuthGrants(ctx.context.newSession.user.id)
1281+
}
1282+
12731283
if (ctx.path === '/oauth2/link' && ctx.body?.providerId === 'apollo') {
12741284
const returned = ctx.context.returned
12751285
if (isRecordLike(returned) && typeof returned.url === 'string') {
@@ -1481,16 +1491,6 @@ export const auth = betterAuth({
14811491
emailType: 'transactional',
14821492
})
14831493

1484-
if (!result.success && result.message.includes('no email service configured')) {
1485-
logger.info('🔑 VERIFICATION CODE FOR LOGIN/SIGNUP', {
1486-
email: data.email,
1487-
otp: data.otp,
1488-
type: data.type,
1489-
validation: validation.checks,
1490-
})
1491-
return
1492-
}
1493-
14941494
if (!result.success) {
14951495
throw new Error(`Failed to send verification code: ${result.message}`)
14961496
}

‎apps/sim/lib/auth/lifecycle-audit.integration.ts‎

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,107 @@ describe('authentication audit history in PostgreSQL', () => {
409409
}
410410
})
411411

412+
it.each([
413+
{ revokeOtherSessions: true, validPassword: true, revoked: true },
414+
{ revokeOtherSessions: false, validPassword: true, revoked: false },
415+
{ revokeOtherSessions: true, validPassword: false, revoked: false },
416+
])(
417+
'password change revocation=$revokeOtherSessions with validPassword=$validPassword preserves connector credentials',
418+
async ({ revokeOtherSessions, validPassword, revoked }) => {
419+
const current = await login()
420+
await login()
421+
const other = await createAdministrator()
422+
const clientId = generateId()
423+
const connectorId = generateId()
424+
const now = new Date()
425+
const expiresAt = new Date(now.getTime() + 86_400_000)
426+
await db.insert(oauthClient).values({
427+
id: clientId,
428+
clientId,
429+
name: 'Password change OAuth fixture',
430+
public: true,
431+
tokenEndpointAuthMethod: 'none',
432+
grantTypes: ['authorization_code', 'refresh_token'],
433+
redirectUris: ['http://127.0.0.1/callback'],
434+
})
435+
try {
436+
for (const owner of [userId, other.id]) {
437+
await db.insert(oauthConsent).values({
438+
id: generateId(),
439+
clientId,
440+
userId: owner,
441+
scopes: ['api:read'],
442+
createdAt: now,
443+
updatedAt: now,
444+
})
445+
await db.insert(oauthTokenFamily).values({
446+
id: generateId(),
447+
clientId,
448+
userId: owner,
449+
createdAt: now,
450+
expiresAt,
451+
})
452+
await db.insert(oauthAccessToken).values({
453+
id: generateId(),
454+
token: generateId(),
455+
clientId,
456+
userId: owner,
457+
scopes: ['api:read'],
458+
createdAt: now,
459+
expiresAt,
460+
})
461+
}
462+
await db.insert(account).values({
463+
id: connectorId,
464+
accountId: generateId(),
465+
userId,
466+
providerId: 'google-meet',
467+
accessToken: 'connector-access-fixture',
468+
refreshToken: 'connector-refresh-fixture',
469+
createdAt: now,
470+
updatedAt: now,
471+
})
472+
473+
const response = await auth.handler(
474+
request(
475+
'/change-password',
476+
{
477+
currentPassword: validPassword ? fixturePassword : 'incorrect',
478+
newPassword: 'Password-change-fixture-new-38!',
479+
revokeOtherSessions,
480+
},
481+
current.cookie
482+
)
483+
)
484+
expect(response.status).toBe(validPassword ? 200 : 400)
485+
expect(await sessionCount()).toBe(revoked ? 1 : 2)
486+
487+
const families = await db
488+
.select()
489+
.from(oauthTokenFamily)
490+
.where(eq(oauthTokenFamily.clientId, clientId))
491+
const accessTokens = await db
492+
.select()
493+
.from(oauthAccessToken)
494+
.where(eq(oauthAccessToken.clientId, clientId))
495+
for (const rows of [families, accessTokens]) {
496+
expect(rows.filter((row) => row.userId === userId)).toHaveLength(revoked ? 0 : 1)
497+
expect(rows.filter((row) => row.userId === other.id)).toHaveLength(1)
498+
}
499+
expect(
500+
await db.select().from(oauthConsent).where(eq(oauthConsent.clientId, clientId))
501+
).toHaveLength(2)
502+
const [connector] = await db.select().from(account).where(eq(account.id, connectorId))
503+
expect(connector).toMatchObject({
504+
accessToken: 'connector-access-fixture',
505+
refreshToken: 'connector-refresh-fixture',
506+
})
507+
} finally {
508+
await db.delete(oauthClient).where(eq(oauthClient.clientId, clientId))
509+
}
510+
}
511+
)
512+
412513
it('scopes an SSO admission refusal to the configured provider organization when the account belongs elsewhere', async () => {
413514
const providerOrganizationId = generateId()
414515
const providerId = generateId()

‎apps/sim/lib/messaging/email/mailer.ts‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,7 @@ export async function sendEmail(options: EmailOptions): Promise<SendEmailResult>
8787
const data = processEmailData(allowed)
8888

8989
if (activeProviders.length === 0) {
90-
logger.info('Email not sent (no email service configured):', {
91-
to: data.to,
92-
subject: data.subject,
93-
from: data.senderEmail,
94-
})
90+
logger.warn('Email not sent: no email service configured')
9591
return MOCK_EMAIL_RESULT
9692
}
9793

0 commit comments

Comments
 (0)