Skip to content

Commit 6fafaf9

Browse files
committed
fix(credentials): read GitHub's UTC-marked token expiration header form
GitHub's octokit.rb spec cassettes record the GitHub-Authentication-Token-Expiration header both with a numeric offset and as 'YYYY-MM-DD HH:MM:SS UTC'. Accept the UTC-marked form as offset zero so those tokens get their expiry recorded; every other zone name stays unread.
1 parent c901a86 commit 6fafaf9

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

‎apps/sim/lib/credentials/token-service-accounts/validators/github.test.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ describe('GitHub saved personal access token verification', () => {
9494
'2026-12-01T10:30:00.000Z',
9595
],
9696
['a timestamp minutes away', '2026-11-11 12:30:00 +0000', '2026-11-11T12:30:00.000Z'],
97+
['a timestamp marked UTC', '2026-12-01 10:30:00 UTC', '2026-12-01T10:30:00.000Z'],
9798
])('records the expiry GitHub reports as %s', async (_, header, expected) => {
9899
fetch.mockResolvedValue(userReply(header))
99100

@@ -105,7 +106,8 @@ describe('GitHub saved personal access token verification', () => {
105106
it.each([
106107
['no expiry header (a token that never expires)', undefined],
107108
['an unreadable expiry', 'next Tuesday'],
108-
['a zone name instead of an offset', '2026-12-01 10:30:00 UTC'],
109+
['a zone name other than UTC', '2026-12-01 10:30:00 PST'],
110+
['a lowercase utc marker', '2026-12-01 10:30:00 utc'],
109111
['an impossible date', '2026-13-45 10:00:00 +0000'],
110112
['an expiry in the past, contradicting the accepted request', '2026-11-10 12:00:00 +0000'],
111113
])('records no expiry for %s and still accepts the token', async (_, header) => {

‎apps/sim/lib/credentials/vendor-token-expiry.ts‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ function calendarMomentUtc(
2727
}
2828

2929
/**
30-
* `2026-12-01 12:30:00 +0200`. GitHub documents the header but not its value format, so this is
31-
* parsed strictly by design: the one form accepted is the one in the API responses GitHub's own
32-
* client library records (octokit/octokit.rb spec cassettes), and any other form is left unread.
30+
* `2026-12-01 12:30:00 +0200` or `2026-12-01 10:30:00 UTC`. GitHub documents the header but not
31+
* its value format, so this is parsed strictly by design: the two forms accepted are the ones in
32+
* the API responses GitHub's own client library records (octokit/octokit.rb spec cassettes), and
33+
* any other form is left unread.
3334
*/
34-
const GITHUB_TOKEN_EXPIRATION = /^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2}) ([+-]\d{4})$/
35+
const GITHUB_TOKEN_EXPIRATION = /^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2}) ([+-]\d{4}|UTC)$/
3536

3637
/**
3738
* Reads GitHub's `GitHub-Authentication-Token-Expiration` response header, which GitHub sends on
@@ -43,8 +44,10 @@ export function githubTokenExpiration(header: string | null): Date | undefined {
4344
if (!match) return undefined
4445
const offset = match[7]
4546
const offsetMinutes =
46-
(offset.startsWith('-') ? -1 : 1) *
47-
(Number(offset.slice(1, 3)) * 60 + Number(offset.slice(3, 5)))
47+
offset === 'UTC'
48+
? 0
49+
: (offset.startsWith('-') ? -1 : 1) *
50+
(Number(offset.slice(1, 3)) * 60 + Number(offset.slice(3, 5)))
4851
return calendarMomentUtc(match.slice(1, 7).map(Number), offsetMinutes)
4952
}
5053

0 commit comments

Comments
 (0)