From 4bd5feef28653ae26482acf94cf31fe310f65960 Mon Sep 17 00:00:00 2001 From: David Cook Date: Thu, 10 Jul 2025 00:41:18 +0000 Subject: [PATCH] Bug 40336: Validate timeout syspref for self-checks This patch validates the numbers passed to the self-check timeout code, so that it must be a valid number >= 10 seconds. If it fails this validation, it defaults to 120 seconds. Test plan: 0. Apply the patch 1. Enable the SelfCheckInModule and WebBasedSelfCheck syspref 2. Try out these modules using varying values in the SelfCheckInTimeout and SelfCheckTimeout system preferences resepectives. For instance: - A blank space (ie " ") - A negative number (e.g. -7) - An alphabetic string (e.g. aa) - A positive number less than 10 (e.g. 5) - A positive number greater than 10 (e.g. 60) 3. Check the "idle_timeout" value set in the timer objects using the following in the browser console: console.log(window.sci_login_timer); console.log(window.sco_login_timer); 4. Note that all cases except positive numbers greater than or equal to 10 get reset to 120 --- koha-tmpl/opac-tmpl/bootstrap/en/modules/sci/sci-main.tt | 2 +- koha-tmpl/opac-tmpl/bootstrap/en/modules/sco/sco-main.tt | 2 +- koha-tmpl/opac-tmpl/bootstrap/js/timeout.js | 7 +++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/sci/sci-main.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/sci/sci-main.tt index 1f9664fc3d..24198def8f 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/sci/sci-main.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/sci/sci-main.tt @@ -301,7 +301,7 @@ function login_timeout(){ //NOTE: There can only be 1 sci_login_timer at a time if ( ! window.sci_login_timer ){ - const idleTimeout = "[% Koha.Preference('SelfCheckInTimeOut') || 120 | html %]"; + const idleTimeout = "[% Koha.Preference('SelfCheckInTimeOut') | html %]"; const home_href = "/cgi-bin/koha/sci/sci-main.pl"; const sci_timer = new sc_timer({ "idle_timeout": idleTimeout, diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/sco/sco-main.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/sco/sco-main.tt index 52227a6b42..899d65904f 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/sco/sco-main.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/sco/sco-main.tt @@ -420,7 +420,7 @@ function login_timeout(){ //NOTE: There can only be 1 sco_login_timer at a time if ( ! window.sco_login_timer ){ - const idleTimeout = "[% Koha.Preference('SelfCheckTimeout') || 120 | html %]"; + const idleTimeout = "[% Koha.Preference('SelfCheckTimeout') | html %]"; const home_href = "/cgi-bin/koha/sco/sco-main.pl?op=logout"; const sco_timer = new sc_timer({ "idle_timeout": idleTimeout, diff --git a/koha-tmpl/opac-tmpl/bootstrap/js/timeout.js b/koha-tmpl/opac-tmpl/bootstrap/js/timeout.js index 6c508d14c0..2e4ad8d389 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/js/timeout.js +++ b/koha-tmpl/opac-tmpl/bootstrap/js/timeout.js @@ -1,9 +1,12 @@ class sc_timer { constructor(args) { - const idle_timeout = args["idle_timeout"]; + const idle_timeout = Number(args["idle_timeout"]); const redirect_url = args["redirect_url"]; - if (idle_timeout) { + const idle_timeout_minimum = 10; + if (idle_timeout && idle_timeout >= idle_timeout_minimum) { this.idle_timeout = idle_timeout; + } else { + this.idle_timeout = 120; } if (redirect_url) { this.redirect_url = redirect_url; -- 2.39.5