GitHub Security Advisory: GHSA-9ffx-f77r-756w
Package: sylius/sylius (COMPOSER)
Severity: MODERATE (CVSS 0.0)
CWE: CWE-601: URL Redirection to Untrusted Site ('Open Redirect')
Vulnerable versions: >= 1.13.0, <= 1.13.14
Patched in: 1.13.15

Summary: Sylius has an Open Redirect via Referer Header

Details:
### Impact
`CurrencySwitchController::switchAction()`, `ImpersonateUserController::impersonateAction()` and `StorageBasedLocaleSwitcher::handle()` use the HTTP Referer header directly when redirecting.

The attack requires the victim to click a legitimate application link placed on an attacker-controlled page. The browser automatically sends the attacker's site as the Referer, and the application redirects back to it. This can be used for phishing or credential theft, as the redirect originates from a trusted domain.

The severity varies by endpoint; public endpoints require no authentication and are trivially exploitable, while admin-only endpoints require an authenticated session but remain vulnerable if an admin follows a link from an external source such as email or chat.

Affected classes:
- `CurrencySwitchController::switchAction()` - public
- `StorageBasedLocaleSwitcher::handle()` - public, used in locale switching without having locale in the `url`
- `ImpersonateUserController::impersonateAction()` - admin-only

### Patches
The issue is fixed in versions: 1.9.12, 1.10.16, 1.11.17, 1.12.23, 1.13.15, 1.14.18, 2.0.16, 2.1.12, 2.2.3 and above.

### Workarounds
If you cannot update Sylius immediately, copy the affected classes from vendor to your project's `src/` directory, apply the fix, and override the service definitions.

#### Step 1 - CurrencySwitchController

Copy from `vendor/sylius/sylius/src/Sylius/Bundle/ShopBundle/Controller/CurrencySwitchController.php` to `src/Controller/CurrencySwitchController.php` and apply the following changes:

```diff
-namespace Sylius\Bundle\ShopBundle\Controller;
+namespace App\Controller;

 use Sylius\Component\Channel\Context\ChannelContextInterface;
 use Sylius\Component\Core\Currency\CurrencyStorageInterface;
 use Sylius\Component\Core\Model\ChannelInterface;
 use Symfony\Component\HttpFoundation\RedirectResponse;
 use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\Routing\RouterInterface;

 final class CurrencySwitchController
 {
     public function __construct(
         private Environment $templatingEngine, // for 1.x version
         private CurrencyStorageInterface $currencyStorage,
         private ChannelContextInterface $channelContext,
+        private RouterInterface $router,
     ) {
     }

     public function switchAction(Request $request, string $code): Response
     {
         /** @var ChannelInterface $channel */
         $channel = $this->channelContext->getChannel();

         $this->currencyStorage->set($channel, $code);

-        return new RedirectResponse($request->headers->get('referer', $request->getSchemeAndHttpHost()));
+        return new RedirectResponse($this->router->generate('sylius_shop_homepage'));
     }
 }
```

#### Step 2 - ImpersonateUserController

Copy from `vendor/sylius/sylius/src/Sylius/Bundle/AdminBundle/Controller/ImpersonateUserController.php` to `src/Controller/Admin/ImpersonateUserContro