From 04d9fa04a751369f6c301bf428732581a8e7915b Mon Sep 17 00:00:00 2001 From: colin-stuart Date: Thu, 12 Sep 2024 09:21:30 -0400 Subject: [PATCH] Auth: Prevent scheduled token rotation jobs with large delay from rolling back to 1 ms (#93242) Auth: prevent scheduled token rotation jobs with large delay from rolling back to 1 ms --- public/app/core/services/context_srv.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/public/app/core/services/context_srv.ts b/public/app/core/services/context_srv.ts index 25f4ed13e1c..aeb1371a855 100644 --- a/public/app/core/services/context_srv.ts +++ b/public/app/core/services/context_srv.ts @@ -197,9 +197,8 @@ export class ContextSrv { // to distribute the scheduling of the job. For now this can be between 1 and 20 seconds const expiresWithDistribution = expires - Math.floor(Math.random() * (20 - 1) + 1); - // nextRun is when the job should be scheduled for - let nextRun = expiresWithDistribution * 1000 - Date.now(); - + // nextRun is when the job should be scheduled for in ms. setTimeout ms has a max value of 2147483647. + let nextRun = Math.min(expiresWithDistribution * 1000 - Date.now(), 2147483647); // @ts-ignore this.tokenRotationJobId = setTimeout(() => { // if we have a new expiry time from the expiry cookie another tab have already performed the rotation