Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ab117c2
New feature: enhance security with custom admin URL.
kiatng Oct 10, 2024
ba01bd1
Check if URL host matches custom admin URL.
kiatng Oct 10, 2024
bebb936
Fixed incorrect 404 error skin when using dev/openmage/nginx-frontend…
kiatng Oct 11, 2024
1639aa6
Merge branch 'main' into custom_admin_url
kiatng Nov 25, 2024
b4b1986
Merge branch 'main' into custom_admin_url
sreichel Jan 11, 2025
659ce5b
Merge branch 'main' into custom_admin_url
kiatng Jan 17, 2025
3ef5be4
Merge branch 'main' into custom_admin_url
kiatng Jan 20, 2025
ab49589
Merge branch 'main' into custom_admin_url
sreichel Jan 22, 2025
c1f9224
Combined 2 if statements
kiatng Jan 22, 2025
bc45ef5
Merge branch 'main' into custom_admin_url
kiatng Feb 13, 2025
47b42cf
Merge branch 'main' into custom_admin_url
sreichel Jul 22, 2025
d1dbe2f
Merge branch 'main' into custom_admin_url
kiatng Sep 25, 2025
49cdc54
Merge branch 'main' into custom_admin_url
addison74 Sep 27, 2025
3c81550
Merge branch 'main' into custom_admin_url
sreichel Sep 30, 2025
65d2da0
Merge branch 'main' into custom_admin_url
sreichel Oct 2, 2025
63cf691
Merge branch 'main' into custom_admin_url
kiatng Oct 4, 2025
a416331
Merge branch 'main' into custom_admin_url
kiatng Oct 7, 2025
45c3eed
Added validation of custom admin url
kiatng Oct 7, 2025
947661f
Removed unnecessary logic in store
kiatng Oct 7, 2025
5421bf7
Merge branch 'custom_admin_url' of https://github.com/kiatng/magento-…
kiatng Oct 7, 2025
4cddb67
Update app/code/core/Mage/Core/Controller/Varien/Router/Admin.php
kiatng Oct 7, 2025
cbfcfa7
remove trim
kiatng Oct 7, 2025
25ec5f0
refactor: improve custom admin URL handling and add redirect flag
kiatng Oct 8, 2025
eab4dc2
Merge branch 'custom_admin_url' of https://github.com/kiatng/magento-…
kiatng Oct 8, 2025
6847e2a
Fix PHP-CS-Fixer
kiatng Oct 9, 2025
14bacb2
refactor: enhance admin domain validation in routing
kiatng Oct 13, 2025
f4cd780
Merge branch 'main' into custom_admin_url
kiatng Oct 13, 2025
1bf211d
Merge branch 'main' into custom_admin_url
sreichel Oct 13, 2025
39b496c
Update app/code/core/Mage/Core/Controller/Varien/Router/Admin.php
sreichel Oct 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions app/code/core/Mage/Adminhtml/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Mage_Adminhtml_Helper_Data extends Mage_Adminhtml_Helper_Help_Mapping
{
public const XML_PATH_ADMINHTML_ROUTER_FRONTNAME = 'admin/routers/adminhtml/args/frontName';
public const XML_PATH_USE_CUSTOM_ADMIN_URL = 'default/admin/url/use_custom';
public const XML_PATH_CUSTOM_ADMIN_URL = 'default/admin/url/custom';
public const XML_PATH_USE_CUSTOM_ADMIN_PATH = 'default/admin/url/use_custom_path';
public const XML_PATH_CUSTOM_ADMIN_PATH = 'default/admin/url/custom_path';
public const XML_PATH_ADMINHTML_SECURITY_USE_FORM_KEY = 'admin/security/use_form_key';
Expand Down Expand Up @@ -78,6 +79,21 @@ public static function getUrl($route = '', $params = [])
return Mage::getModel('adminhtml/url')->getUrl($route, $params);
}

/**
* @return string|false
*/
public static function getCustomAdminUrl()
{
$config = Mage::getConfig();
if ($config->getNode(self::XML_PATH_USE_CUSTOM_ADMIN_URL)
&& $config->getNode(self::XML_PATH_CUSTOM_ADMIN_URL)
) {
return (string) $config->getNode(self::XML_PATH_CUSTOM_ADMIN_URL);
}

return false;
}

/**
* @return false|int
*/
Expand Down
16 changes: 16 additions & 0 deletions app/code/core/Mage/Core/Controller/Varien/Router/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,20 @@ protected function _validateControllerInstance($controllerInstance)
{
return true;
}

/**
* Check if URL host matches custom admin URL.
*
* @inheritDoc
*/
public function match(Zend_Controller_Request_Http $request)
{
if (($adminUrl = Mage_Adminhtml_Helper_Data::getCustomAdminUrl())
&& !str_contains($adminUrl, $request->getHttpHost())
) {
return false;
}

return parent::match($request);
}
}
10 changes: 9 additions & 1 deletion app/code/core/Mage/Core/Model/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,15 @@ public function getBaseUrl($type = self::URL_TYPE_LINK, $secure = null)
$url = str_replace('{{base_url}}', $baseUrl, $url);
}

$this->_baseUrlCache[$cacheKey] = rtrim($url, '/') . '/';
$url = rtrim($url, '/') . '/';
$adminUrl = $this->isAdmin() ? Mage_Adminhtml_Helper_Data::getCustomAdminUrl() : false;
if ($adminUrl) {
$adminUrl = rtrim($adminUrl, '/') . '/';
$baseUrl = str_starts_with($url, 'https://') ? $this->getConfig(self::XML_PATH_SECURE_BASE_URL) : $this->getConfig(self::XML_PATH_UNSECURE_BASE_URL);
$url = str_replace($baseUrl, $adminUrl, $url);
}

$this->_baseUrlCache[$cacheKey] = $url;
}

return $this->_baseUrlCache[$cacheKey];
Expand Down
4 changes: 1 addition & 3 deletions errors/processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,7 @@ protected function _validate(): bool
*/
protected function _setSkin(string $value, ?stdClass $config = null)
{
if (preg_match('/^[a-z0-9_]+$/i', $value)
&& is_dir($this->_indexDir . self::ERROR_DIR . '/' . $value)
) {
if (preg_match('/^[a-z0-9_]+$/i', $value) && is_dir($this->_errorDir . $value)) {
if (!$config && $this->_config) {
$config = $this->_config;
}
Expand Down
Loading