Skip to content

Going to '/admin' while using storecodes in url and a different adminhtml url will throw exception #11140

Closed
@koenner01

Description

@koenner01

If you are using an adminhtml url that is different from 'admin' and set the 'Add Store Code to Urls' to 'Yes', going to '/admin' will throw an exception

Preconditions

  1. PHP7.0
  2. M2.1.9 CE (we also tested 2.1.7 CE and 2.2.0 CE)

Steps to reproduce

  1. use a different url than 'admin' for the adminhtml
  2. set 'Stores' > 'Configuration' > 'General' > 'Web' > 'Add Store Code to Urls' to 'Yes'
  3. go to '/admin' url

Expected result

  1. Page should go to the no-route or at least show 404

Actual result

  1. Page tries to go to the homepage with the current store set to 'admin'

We did some debugging already and found that in \Magento\Store\App\Request\PathInfoProcessor the current store is being set to 'admin'.

public function process(\Magento\Framework\App\RequestInterface $request, $pathInfo)
{
    $pathParts = explode('/', ltrim($pathInfo, '/'), 2);
    $storeCode = $pathParts[0];
    try {
        /** @var \Magento\Store\Api\Data\StoreInterface $store */
        $store = $this->storeManager->getStore($storeCode);
    } catch (NoSuchEntityException $e) {
        return $pathInfo;
    }
    if ($store->isUseStoreInUrl()) {
        if (!$request->isDirectAccessFrontendName($storeCode)) {
            $this->storeManager->setCurrentStore($storeCode);
            $pathInfo = '/' . (isset($pathParts[1]) ? $pathParts[1] : '');
            return $pathInfo;
        } elseif (!empty($storeCode)) {
            $request->setActionName('noroute');
            return $pathInfo;
        }
        return $pathInfo;
    }
    return $pathInfo;
}

'admin' will be treated as a valid storecode because the store table in the database contains this value for the store with id 0

Metadata

Metadata

Assignees

Labels

Fixed in 2.1.xThe issue has been fixed in 2.1 release lineFixed in 2.2.xThe issue has been fixed in 2.2 release lineFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releaseReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions