From 12d99a9ad552dab0e4bdcb313e049c79f5fa2a9f Mon Sep 17 00:00:00 2001 From: Pavel Horal Date: Sun, 23 Jun 2024 19:50:30 +0200 Subject: [PATCH] Fix session validation error in WebKit browsers (#176) --- .../ui/user/services/SessionService.jsm | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/openam-ui/openam-ui-ria/src/main/js/org/forgerock/openam/ui/user/services/SessionService.jsm b/openam-ui/openam-ui-ria/src/main/js/org/forgerock/openam/ui/user/services/SessionService.jsm index 76bcde0279..2b662f80f4 100644 --- a/openam-ui/openam-ui-ria/src/main/js/org/forgerock/openam/ui/user/services/SessionService.jsm +++ b/openam-ui/openam-ui-ria/src/main/js/org/forgerock/openam/ui/user/services/SessionService.jsm @@ -15,6 +15,7 @@ * Portions copyright 2024 Wren Security. */ +import $ from "jquery"; import _ from "lodash"; import { sessionAddInfo } from "store/actions/creators"; @@ -37,11 +38,25 @@ const getSessionInfo = (options) => { }; export const getTimeLeft = () => { - return getSessionInfo({ suppressSpinner: true }).then((sessionInfo) => { - const idleExpiration = moment(sessionInfo.maxIdleExpirationTime).diff(moment(), "seconds"); - const maxExpiration = moment(sessionInfo.maxSessionExpirationTime).diff(moment(), "seconds"); - return _.min([idleExpiration, maxExpiration]); - }); + // Number of seconds to indicate in case of network error (see WrenSecurity/wrenam#176) + const NETWORK_ERROR_EXPIRATION_SECONDS = 30; + + return getSessionInfo({ + suppressEvents: true, + suppressSpinner: true, + }).then( + (sessionInfo) => { + const idleExpiration = moment(sessionInfo.maxIdleExpirationTime).diff(moment(), "seconds"); + const maxExpiration = moment(sessionInfo.maxSessionExpirationTime).diff(moment(), "seconds"); + return _.min([idleExpiration, maxExpiration]); + }, + (jqXhr, textStatus, errorThrown) => { + if (jqXhr.status === 0) { // ignore network error + return $.Deferred().resolve(NETWORK_ERROR_EXPIRATION_SECONDS); + } + return $.Deferred().reject(jqXhr, textStatus, errorThrown); + } + ); }; export const updateSessionInfo = (options) => {