11<?php
22/**
3- *
43 * Copyright © Magento, Inc. All rights reserved.
54 * See COPYING.txt for license details.
65 */
76namespace Magento \Backend \Controller \Adminhtml \Auth ;
87
8+ use Magento \Backend \App \Area \FrontNameResolver ;
9+ use Magento \Backend \Model \UrlFactory ;
910use Magento \Framework \App \Action \HttpGetActionInterface as HttpGet ;
1011use Magento \Framework \App \Action \HttpPostActionInterface as HttpPost ;
12+ use Magento \Framework \App \ObjectManager ;
1113
1214/**
1315 * @api
@@ -20,18 +22,34 @@ class Login extends \Magento\Backend\Controller\Adminhtml\Auth implements HttpGe
2022 */
2123 protected $ resultPageFactory ;
2224
25+ /**
26+ * @var FrontNameResolver
27+ */
28+ private $ frontNameResolver ;
29+
30+ /**
31+ * @var UrlFactory
32+ */
33+ private $ backendUrlFactory ;
34+
2335 /**
2436 * Constructor
2537 *
2638 * @param \Magento\Backend\App\Action\Context $context
2739 * @param \Magento\Framework\View\Result\PageFactory $resultPageFactory
40+ * @param FrontNameResolver $frontNameResolver
41+ * @param UrlFactory $backendUrlFactory
2842 */
2943 public function __construct (
3044 \Magento \Backend \App \Action \Context $ context ,
31- \Magento \Framework \View \Result \PageFactory $ resultPageFactory
45+ \Magento \Framework \View \Result \PageFactory $ resultPageFactory ,
46+ FrontNameResolver $ frontNameResolver = null ,
47+ UrlFactory $ backendUrlFactory = null
3248 ) {
3349 $ this ->resultPageFactory = $ resultPageFactory ;
3450 parent ::__construct ($ context );
51+ $ this ->frontNameResolver = $ frontNameResolver ?? ObjectManager::getInstance ()->get (FrontNameResolver::class);
52+ $ this ->backendUrlFactory = $ backendUrlFactory ?? ObjectManager::getInstance ()->get (UrlFactory::class);
3553 }
3654
3755 /**
@@ -49,7 +67,8 @@ public function execute()
4967 }
5068
5169 $ requestUrl = $ this ->getRequest ()->getUri ();
52- if (!$ requestUrl ->isValid ()) {
70+
71+ if (!$ requestUrl ->isValid () || !$ this ->isValidBackendUri ()) {
5372 return $ this ->getRedirect ($ this ->getUrl ('* ' ));
5473 }
5574
@@ -69,4 +88,18 @@ private function getRedirect($path)
6988 $ resultRedirect ->setPath ($ path );
7089 return $ resultRedirect ;
7190 }
91+
92+ /**
93+ * Verify if correct backend uri requested.
94+ *
95+ * @return bool
96+ */
97+ private function isValidBackendUri (): bool
98+ {
99+ $ backendFrontName = $ this ->frontNameResolver ->getFrontName ();
100+ $ requestUri = $ this ->getRequest ()->getRequestUri ();
101+ $ baseUrl = parse_url ($ this ->backendUrlFactory ->create ()->getBaseUrl (), PHP_URL_PATH );
102+
103+ return strpos ($ requestUri , $ baseUrl . $ backendFrontName ) === 0 ;
104+ }
72105}
0 commit comments