CVE-2024-23648: Improper Neutralization of Special Elements in Output Used by a Downstream Component ('Injection') (CWE-74)
value: Pimcore's Admin Classic Bundle provides a backend user interface for Pimcore. The password reset functionality sends to the the user requesting a password change an email containing an URL to reset its password. The URL sent contains a unique token, valid during 24 hours, allowing the user to reset its password. This token is highly sensitive ; as an attacker able to retrieve it would be able to resets the user's password. Prior to version 1.2.3, the reset-password URL is crafted using the "Host" HTTP header of the request sent to request a password reset. This way, an external attacker could send password requests for users, but specify a "Host" header of a website that they control. If the user receiving the mail clicks on the link, the attacker would retrieve the reset token of the victim and perform account takeover. Version 1.2.3 fixes this issue.
CWE description: The product constructs all or part of a command, data structure, or record using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify how it is parsed or interpreted when it is sent to a downstream component.
CVSS v3 base score: 8.8
Published: 2024-01-24T18:15Z
Repository: https://github.com/pimcore/admin-ui-classic-bundle
Language: PHP
Files changed: src/Controller/Admin/LoginController.php
Commit date: 2023-12-06 12:35:56 +0100
Commit message: Password reset - fix for possible host header injection (#362)

* Password reset - fix for possible host header injection

* Update src/Controller/Admin/LoginController.php

Co-authored-by: Sebastian Blank <blank@data-factory.net>

---------

Co-authored-by: Sebastian Blank <blank@data-factory.net>
Diff: diff --git a/src/Controller/Admin/LoginController.php b/src/Controller/Admin/LoginController.php
index 973b9eebc3..a5fb774c90 100644
--- a/src/Controller/Admin/LoginController.php
+++ b/src/Controller/Admin/LoginController.php
@@ -30,10 +30,11 @@ use Pimcore\Controller\KernelResponseEventInterface;
 use Pimcore\Extension\Bundle\PimcoreBundleManager;
 use Pimcore\Http\ResponseHelper;
 use Pimcore\Logger;
 use Pimcore\Model\User;
 use Pimcore\Security\SecurityHelper;
+use Pimcore\SystemSettingsConfig;
 use Pimcore\Tool;
 use Pimcore\Tool\Authentication;
 use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\Google\GoogleAuthenticatorInterface;
 use Symfony\Component\EventDispatcher\GenericEvent;
 use Symfony\Component\HttpFoundation\RedirectResponse;
@@ -42,10 +43,11 @@ use Symfony\Component\HttpFoundation\Response;
 use Symfony\Component\HttpKernel\Event\ControllerEvent;
 use Symfony\Component\HttpKernel\Event\ResponseEvent;
 use Symfony\Component\RateLimiter\RateLimiterFactory;
 use Symfony\Component\Routing\Annotation\Route;
 use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
+use Symfony\Component\Routing\RouterInterface;
 use Symfony\Component\Security\Core\Exception\AuthenticationException;
 use Symfony\Component\Security\Core\Security;
 use Symfony\Component\Security\Core\User\UserInterface;
 use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
 use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
@@ -192,11 +194,17 @@ class LoginController extends AdminAbstractController implements KernelControlle
     }
 
     /**
      * @Route("/login/lostpassword", name="pimcore_admin_login_lostpassword")
      */
-    public function lostpasswordAction(Request $request, CsrfProtectionHandler $csrfProtection, Config $config, RateLimiterFactory $resetPasswordLimiter): Response
+    public function lostpasswordAction(
+        Request $request,
+        CsrfProtectionHandler $csrfProtection,
+        Config $config,
+        RateLimiterFactory $resetPasswordLimiter,
+        RouterInterface $router
+    ): Response
     {
         $params = $this->buildLoginPageViewParams($config);
         $error = null;
 
         if ($request->getMethod() === 'POST' && $username = $request->get('username')) {
@@ -224,16 +232,24 @@ class LoginController extends AdminAbstractController implements KernelControlle
             }
 
             if (!$error) {
                 $token = Authentication::generateTokenByUser($user);
 
-                $loginUrl = $this->generateUrl('pimcore_admin_login_check', [
-                    'token' => $token,
-                    'reset' => 'true',
-                ], UrlGeneratorInterface::ABSOLUTE_URL);
-
                 try {
+                    $domain = SystemSettingsConfig::get()['general']['domain'];
+                    if (!$domain) {
+                        throw new \Exception('No main domain set in system settings, unable to generate reset password link');
+                    }
+
+                    $context = $router->getContext();
+                    $context->setHost($domain);
+
+                    $loginUrl = $this->generateUrl('pimcore_admin_login_check', [
+                        'token' => $token,
+                        'reset' => 'true',
+                    ], UrlGeneratorInterface::ABSOLUTE_URL);
+
                     $event = new LostPasswordEvent($user, $loginUrl);
                     $this->eventDispatcher->dispatch($event, AdminEvents::LOGIN_LOSTPASSWORD);
 
                     // only send mail if it wasn't prevented in event
                     if ($event->getSendMail()) {

Vulnerable code:     public function lostpasswordAction(Request $request, CsrfProtectionHandler $csrfProtection, Config $config, RateLimiterFactory $resetPasswordLimiter): Response
                $loginUrl = $this->generateUrl('pimcore_admin_login_check', [
                    'token' => $token,
                    'reset' => 'true',
                ], UrlGeneratorInterface::ABSOLUTE_URL);

Fixed code: use Pimcore\SystemSettingsConfig;
use Symfony\Component\Routing\RouterInterface;
    public function lostpasswordAction(
        Request $request,
        CsrfProtectionHandler $csrfProtection,
        Config $config,
        RateLimiterFactory $resetPasswordLimiter,
        RouterInterface $router
    ): Response
                    $domain = SystemSettingsConfig::get()['general']['domain'];
                    if (!$domain) {
                        throw new \Exception('No main domain set in system settings, unable to generate reset password link');
                    }

                    $context = $router->getContext();
                    $context->setHost($domain);

                    $loginUrl = $this->generateUrl('pimcore_admin_login_check', [
                        'token' => $token,
                        'reset' => 'true',
                    ], UrlGeneratorInterface::ABSOLUTE_URL);