Skip to content

Commit c2b126b

Browse files
Reduce App Check custom token exp to 5 mins (#1372)
1 parent 4e816f4 commit c2b126b

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/app-check/token-generator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ import { HttpError } from '../utils/api-request';
3030

3131
import AppCheckTokenOptions = appCheck.AppCheckTokenOptions;
3232

33-
const ONE_HOUR_IN_SECONDS = 60 * 60;
34-
const ONE_MINUTE_IN_MILLIS = 60 * 1000;
33+
const ONE_MINUTE_IN_SECONDS = 60;
34+
const ONE_MINUTE_IN_MILLIS = ONE_MINUTE_IN_SECONDS * 1000;
3535
const ONE_DAY_IN_MILLIS = 24 * 60 * 60 * 1000;
3636

3737
// Audience to use for Firebase App Check Custom tokens
@@ -91,7 +91,7 @@ export class AppCheckTokenGenerator {
9191
// eslint-disable-next-line @typescript-eslint/camelcase
9292
app_id: appId,
9393
aud: FIREBASE_APP_CHECK_AUDIENCE,
94-
exp: iat + ONE_HOUR_IN_SECONDS,
94+
exp: iat + (ONE_MINUTE_IN_SECONDS * 5),
9595
iat,
9696
...customOptions,
9797
};

test/unit/app-check/token-generator.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ chai.use(chaiAsPromised);
4343
const expect = chai.expect;
4444

4545
const ALGORITHM = 'RS256';
46-
const ONE_HOUR_IN_SECONDS = 60 * 60;
46+
const FIVE_MIN_IN_SECONDS = 60 * 5;
4747
const FIREBASE_APP_CHECK_AUDIENCE = 'https://firebaseappcheck.googleapis.com/google.firebase.appcheck.v1beta.TokenExchangeService';
4848

4949
/**
@@ -184,7 +184,7 @@ describe('AppCheckTokenGenerator', () => {
184184
// eslint-disable-next-line @typescript-eslint/camelcase
185185
app_id: APP_ID,
186186
iat: 1,
187-
exp: ONE_HOUR_IN_SECONDS + 1,
187+
exp: FIVE_MIN_IN_SECONDS + 1,
188188
aud: FIREBASE_APP_CHECK_AUDIENCE,
189189
iss: mocks.certificateObject.client_email,
190190
sub: mocks.certificateObject.client_email,
@@ -205,7 +205,7 @@ describe('AppCheckTokenGenerator', () => {
205205
// eslint-disable-next-line @typescript-eslint/camelcase
206206
app_id: APP_ID,
207207
iat: 1,
208-
exp: ONE_HOUR_IN_SECONDS + 1,
208+
exp: FIVE_MIN_IN_SECONDS + 1,
209209
aud: FIREBASE_APP_CHECK_AUDIENCE,
210210
iss: mocks.certificateObject.client_email,
211211
sub: mocks.certificateObject.client_email,
@@ -233,7 +233,7 @@ describe('AppCheckTokenGenerator', () => {
233233
// eslint-disable-next-line @typescript-eslint/camelcase
234234
app_id: APP_ID,
235235
iat: 1,
236-
exp: ONE_HOUR_IN_SECONDS + 1,
236+
exp: FIVE_MIN_IN_SECONDS + 1,
237237
aud: FIREBASE_APP_CHECK_AUDIENCE,
238238
iss: mocks.certificateObject.client_email,
239239
sub: mocks.certificateObject.client_email,
@@ -275,15 +275,15 @@ describe('AppCheckTokenGenerator', () => {
275275
});
276276
});
277277

278-
it('should be fulfilled with a JWT which expires after one hour', () => {
278+
it('should be fulfilled with a JWT which expires after five minutes', () => {
279279
clock = sinon.useFakeTimers(1000);
280280

281281
let token: string;
282282
return tokenGenerator.createCustomToken(APP_ID)
283283
.then((result) => {
284284
token = result;
285285

286-
clock!.tick((ONE_HOUR_IN_SECONDS * 1000) - 1);
286+
clock!.tick((FIVE_MIN_IN_SECONDS * 1000) - 1);
287287

288288
// Token should still be valid
289289
return verifyToken(token, mocks.keyPairs[0].public);

0 commit comments

Comments
 (0)