Skip to content

fix(auth): Add missing Math.floor() when setting validDuration in createSessionCookie() #2712

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

Merged
merged 3 commits into from
Sep 25, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/auth/auth-api-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@ export abstract class AbstractAuthRequestHandler {
const request = {
idToken,
// Convert to seconds.
validDuration: expiresIn / 1000,
validDuration: Math.floor(expiresIn / 1000),
};
return this.invokeRequestHandler(this.getAuthUrlBuilder(), FIREBASE_AUTH_CREATE_SESSION_COOKIE, request)
.then((response: any) => response.sessionCookie);
Expand Down
2 changes: 1 addition & 1 deletion test/integration/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2563,7 +2563,7 @@ describe('admin.auth', () => {
describe('createSessionCookie()', () => {
let expectedExp: number;
let expectedIat: number;
const expiresIn = 24 * 60 * 60 * 1000;
const expiresIn = (24 * 60 * 60 * 1000) + 234;
let payloadClaims: any;
let currentIdToken: string;
const uid = sessionCookieUids[0];
Expand Down
3 changes: 2 additions & 1 deletion test/unit/auth/auth-api-request.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,8 @@ AUTH_REQUEST_HANDLER_TESTS.forEach((handler) => {
const expectedError = new FirebaseAuthError(
AuthClientErrorCode.INVALID_SESSION_COOKIE_DURATION,
);
const outOfBoundDuration = 60 * 60 * 1000 * 24 * 14 + 1;
// Add more than a second since this value is Math.floor()'ed
const outOfBoundDuration = 60 * 60 * 1000 * 24 * 14 + 1001;

const requestHandler = handler.init(mockApp);
return requestHandler.createSessionCookie('ID_TOKEN', outOfBoundDuration)
Expand Down