Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Reduce App Check custom token exp to 5 mins #1372

Merged
merged 1 commit into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/app-check/token-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import { HttpError } from '../utils/api-request';

import AppCheckTokenOptions = appCheck.AppCheckTokenOptions;

const ONE_HOUR_IN_SECONDS = 60 * 60;
const ONE_MINUTE_IN_MILLIS = 60 * 1000;
const ONE_MINUTE_IN_SECONDS = 60;
const ONE_MINUTE_IN_MILLIS = ONE_MINUTE_IN_SECONDS * 1000;
const ONE_DAY_IN_MILLIS = 24 * 60 * 60 * 1000;

// Audience to use for Firebase App Check Custom tokens
Expand Down Expand Up @@ -91,7 +91,7 @@ export class AppCheckTokenGenerator {
// eslint-disable-next-line @typescript-eslint/camelcase
app_id: appId,
aud: FIREBASE_APP_CHECK_AUDIENCE,
exp: iat + ONE_HOUR_IN_SECONDS,
exp: iat + (ONE_MINUTE_IN_SECONDS * 5),
iat,
...customOptions,
};
Expand Down
12 changes: 6 additions & 6 deletions test/unit/app-check/token-generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ chai.use(chaiAsPromised);
const expect = chai.expect;

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

/**
Expand Down Expand Up @@ -184,7 +184,7 @@ describe('AppCheckTokenGenerator', () => {
// eslint-disable-next-line @typescript-eslint/camelcase
app_id: APP_ID,
iat: 1,
exp: ONE_HOUR_IN_SECONDS + 1,
exp: FIVE_MIN_IN_SECONDS + 1,
aud: FIREBASE_APP_CHECK_AUDIENCE,
iss: mocks.certificateObject.client_email,
sub: mocks.certificateObject.client_email,
Expand All @@ -205,7 +205,7 @@ describe('AppCheckTokenGenerator', () => {
// eslint-disable-next-line @typescript-eslint/camelcase
app_id: APP_ID,
iat: 1,
exp: ONE_HOUR_IN_SECONDS + 1,
exp: FIVE_MIN_IN_SECONDS + 1,
aud: FIREBASE_APP_CHECK_AUDIENCE,
iss: mocks.certificateObject.client_email,
sub: mocks.certificateObject.client_email,
Expand Down Expand Up @@ -233,7 +233,7 @@ describe('AppCheckTokenGenerator', () => {
// eslint-disable-next-line @typescript-eslint/camelcase
app_id: APP_ID,
iat: 1,
exp: ONE_HOUR_IN_SECONDS + 1,
exp: FIVE_MIN_IN_SECONDS + 1,
aud: FIREBASE_APP_CHECK_AUDIENCE,
iss: mocks.certificateObject.client_email,
sub: mocks.certificateObject.client_email,
Expand Down Expand Up @@ -275,15 +275,15 @@ describe('AppCheckTokenGenerator', () => {
});
});

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

let token: string;
return tokenGenerator.createCustomToken(APP_ID)
.then((result) => {
token = result;

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

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