Skip to content

Commit 311d32e

Browse files
Bill LeoutsakosBill Leoutsakos
authored andcommitted
fix(oauth): reject invalid refresh lifetimes
1 parent cbc74bf commit 311d32e

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

apps/sim/lib/oauth/oauth.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,27 @@ describe('OAuth Token Refresh', () => {
503503
})
504504
})
505505

506+
it.concurrent.each([0, -1, '0', '-1'])(
507+
'should fall back when token expiry is not positive: %s',
508+
async (expiresIn) => {
509+
const mockFetch = vi.fn().mockResolvedValue(
510+
Response.json({
511+
access_token: 'new_access_token',
512+
expires_in: expiresIn,
513+
})
514+
)
515+
516+
const result = await withMockFetch(mockFetch, () =>
517+
refreshOAuthToken('google', 'old_refresh_token')
518+
)
519+
520+
expect(result).toMatchObject({
521+
ok: true,
522+
expiresIn: 3600,
523+
})
524+
}
525+
)
526+
506527
it.concurrent('should handle providers that return new refresh tokens', async () => {
507528
const refreshToken = 'old_refresh_token'
508529
const newRefreshToken = 'new_refresh_token'

apps/sim/lib/oauth/oauth.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1891,7 +1891,8 @@ export async function refreshOAuthToken(
18911891
: typeof expiresInCandidate === 'string' && expiresInCandidate.trim()
18921892
? Number(expiresInCandidate)
18931893
: Number.NaN
1894-
const expiresIn = Number.isFinite(parsedExpiresIn) ? parsedExpiresIn : 3600
1894+
const expiresIn =
1895+
Number.isFinite(parsedExpiresIn) && parsedExpiresIn > 0 ? parsedExpiresIn : 3600
18951896

18961897
if (!accessToken) {
18971898
logger.warn('No access token found in refresh response', {

0 commit comments

Comments
 (0)