From 64d6d7494238783529130020a61c1ff157306374 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Tue, 21 Jan 2025 21:27:21 +0000 Subject: [PATCH] MDL-84275 factor_totp: format site fullname for authenticator setup. --- admin/tool/mfa/factor/totp/classes/factor.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/admin/tool/mfa/factor/totp/classes/factor.php b/admin/tool/mfa/factor/totp/classes/factor.php index 131b9dd4081..3068d570161 100644 --- a/admin/tool/mfa/factor/totp/classes/factor.php +++ b/admin/tool/mfa/factor/totp/classes/factor.php @@ -34,6 +34,7 @@ use tool_mfa\local\factor\object_factor_base; use OTPHP\TOTP; use stdClass; use core\clock; +use core\context\system; use core\di; /** @@ -90,7 +91,7 @@ class factor extends object_factor_base { public function generate_totp_uri(string $secret): string { global $USER, $SITE, $CFG; $host = parse_url($CFG->wwwroot, PHP_URL_HOST); - $sitename = str_replace(':', '', $SITE->fullname); + $sitename = str_replace(':', '', format_string($SITE->fullname, true, ['context' => system::instance()])); $issuer = $sitename.' '.$host; $totp = TOTP::create($secret, clock: $this->clock); $totp->setLabel($USER->username); @@ -190,13 +191,15 @@ class factor extends object_factor_base { $secret = wordwrap($secret, 4, ' ', true) . ''; $secret = \html_writer::tag('code', $secret); + $sitefullname = format_string($SITE->fullname, true, ['context' => system::instance()]); + $manualtable = new \html_table(); $manualtable->id = 'manualattributes'; $manualtable->attributes['class'] = 'generaltable table table-bordered table-sm w-auto'; $manualtable->attributes['style'] = 'width: auto;'; $manualtable->data = [ [get_string('setupfactor:key', 'factor_totp'), $secret], - [get_string('setupfactor:account', 'factor_totp'), "$SITE->fullname ($USER->username)"], + [get_string('setupfactor:account', 'factor_totp'), "{$sitefullname} ({$USER->username})"], [get_string('setupfactor:mode', 'factor_totp'), get_string('setupfactor:mode:timebased', 'factor_totp')], ];