From 9ae69c47fda4243055fe2e57802e6a17e87b3a63 Mon Sep 17 00:00:00 2001 From: briskt <3172830+briskt@users.noreply.github.com> Date: Fri, 24 May 2024 17:14:56 +0800 Subject: [PATCH 1/4] fix exception thrown when a user's password is about to expire This error was shown in the browser: ``` SimpleSAML\Error\Error: UNHANDLEDEXCEPTION Backtrace: 1 www/_include.php:20 (SimpleSAML_exception_handler) 0 [builtin] (N/A) Caused by: TypeError: str_replace(): Argument #2 ($replace) must be of type array|string, float given Backtrace: 7 lib/SimpleSAML/Locale/Translate.php:308 (str_replace) 6 lib/SimpleSAML/Locale/Translate.php:308 (SimpleSAML\Locale\Translate::t) 5 lib/SimpleSAML/XHTML/Template.php:914 (SimpleSAML\XHTML\Template::t) 4 modules/material/themes/material/expirychecker/about2expire.php:34 (require) 3 lib/SimpleSAML/XHTML/Template.php:560 (SimpleSAML\XHTML\Template::show) 2 modules/expirychecker/www/about2expire.php:63 (require) 1 lib/SimpleSAML/Module.php:266 (SimpleSAML\Module::process) 0 www/module.php:10 (N/A) ``` --- modules/expirychecker/lib/Auth/Process/ExpiryDate.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/expirychecker/lib/Auth/Process/ExpiryDate.php b/modules/expirychecker/lib/Auth/Process/ExpiryDate.php index 0275dffb..da8edfc4 100644 --- a/modules/expirychecker/lib/Auth/Process/ExpiryDate.php +++ b/modules/expirychecker/lib/Auth/Process/ExpiryDate.php @@ -118,7 +118,7 @@ protected function getAttribute($attributeName, $state) * expire. * @return int The number of days remaining */ - protected function getDaysLeftBeforeExpiry($expiryTimestamp) + protected function getDaysLeftBeforeExpiry($expiryTimestamp): int { $now = time(); $end = $expiryTimestamp; @@ -389,7 +389,7 @@ protected function redirectToWarningPage(&$state, $accountName, $expiryTimestamp ])); $daysLeft = $this->getDaysLeftBeforeExpiry($expiryTimestamp); - $state['daysLeft'] = $daysLeft; + $state['daysLeft'] = (string)$daysLeft; if (isset($state['isPassive']) && $state['isPassive'] === true) { /* We have a passive request. Skip the warning. */ From e3730cc755effbfaa3ffafec6a621a91d7a50fc8 Mon Sep 17 00:00:00 2001 From: briskt <3172830+briskt@users.noreply.github.com> Date: Fri, 24 May 2024 17:16:19 +0800 Subject: [PATCH 2/4] fix exception thrown when a user is low on printable codes This error was shown in the browser: ``` SimpleSAML\Error\Error: UNHANDLEDEXCEPTION Backtrace: 1 www/_include.php:20 (SimpleSAML_exception_handler) 0 [builtin] (N/A) Caused by: TypeError: str_replace(): Argument #2 ($replace) must be of type array|string, int given Backtrace: 7 lib/SimpleSAML/Locale/Translate.php:308 (str_replace) 6 lib/SimpleSAML/Locale/Translate.php:308 (SimpleSAML\Locale\Translate::t) 5 lib/SimpleSAML/XHTML/Template.php:914 (SimpleSAML\XHTML\Template::t) 4 modules/material/themes/material/mfa/low-on-backup-codes.php:32 (require) 3 lib/SimpleSAML/XHTML/Template.php:560 (SimpleSAML\XHTML\Template::show) 2 modules/mfa/www/low-on-backup-codes.php:35 (require) 1 lib/SimpleSAML/Module.php:266 (SimpleSAML\Module::process) 0 www/module.php:10 (N/A) ``` --- modules/mfa/lib/Auth/Process/Mfa.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/mfa/lib/Auth/Process/Mfa.php b/modules/mfa/lib/Auth/Process/Mfa.php index ecf95aa8..44b475eb 100644 --- a/modules/mfa/lib/Auth/Process/Mfa.php +++ b/modules/mfa/lib/Auth/Process/Mfa.php @@ -761,7 +761,7 @@ protected static function redirectToLowOnBackupCodesNag( $numBackupCodesRemaining ) { $state['employeeId'] = $employeeId; - $state['numBackupCodesRemaining'] = $numBackupCodesRemaining; + $state['numBackupCodesRemaining'] = (string)$numBackupCodesRemaining; $stateId = State::saveState($state, self::STAGE_SENT_TO_LOW_ON_BACKUP_CODES_NAG); $url = Module::getModuleURL('mfa/low-on-backup-codes.php'); From ac6b1c2d27dc4e3ea5297d5ef65499ffb1783330 Mon Sep 17 00:00:00 2001 From: briskt <3172830+briskt@users.noreply.github.com> Date: Mon, 27 May 2024 18:30:05 +0800 Subject: [PATCH 3/4] remove the cast to int --- modules/material/themes/material/mfa/low-on-backup-codes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/material/themes/material/mfa/low-on-backup-codes.php b/modules/material/themes/material/mfa/low-on-backup-codes.php index 152207dd..b8d75d41 100644 --- a/modules/material/themes/material/mfa/low-on-backup-codes.php +++ b/modules/material/themes/material/mfa/low-on-backup-codes.php @@ -29,7 +29,7 @@

- t('{material:mfa:running_out_info}', ['{numBackupCodesRemaining}' => (int)$this->data['numBackupCodesRemaining']]) ?> + t('{material:mfa:running_out_info}', ['{numBackupCodesRemaining}' => $this->data['numBackupCodesRemaining']]) ?>

From 58518071e42e6267eb4c99312d14aee35d874b4e Mon Sep 17 00:00:00 2001 From: briskt <3172830+briskt@users.noreply.github.com> Date: Mon, 27 May 2024 22:05:32 +0800 Subject: [PATCH 4/4] ensure daysLeft is int --- modules/material/themes/material/expirychecker/about2expire.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/material/themes/material/expirychecker/about2expire.php b/modules/material/themes/material/expirychecker/about2expire.php index 59e8f0fe..a8f1cccc 100644 --- a/modules/material/themes/material/expirychecker/about2expire.php +++ b/modules/material/themes/material/expirychecker/about2expire.php @@ -27,7 +27,7 @@

data['daysLeft'] ?? 0; + $daysLeft = $this->data['daysLeft'] ?? '0'; $expiringMessage = $daysLeft < 2 ? $this->t('{material:about2expire:expiring_in_a_day}') : $this->t('{material:about2expire:expiring_soon}',