Skip to content

Commit

Permalink
Merge pull request #177 from pavelhoral/fix-webkit-error
Browse files Browse the repository at this point in the history
Fix session validation error in WebKit browsers
  • Loading branch information
fyrbach authored Jun 25, 2024
2 parents b615c23 + d15f97d commit 27e74ad
Showing 1 changed file with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* Portions copyright 2024 Wren Security.
*/

import $ from "jquery";
import _ from "lodash";

import { sessionAddInfo } from "store/actions/creators";
Expand All @@ -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) => {
Expand Down

0 comments on commit 27e74ad

Please sign in to comment.