-
-
Notifications
You must be signed in to change notification settings - Fork 451
New feature: enhance security with custom admin URL. #4264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I did a quick test ... It seems it needs some documentation. Changes to .htaccess etc ... I tried with apache (DDEV), added addtional host names, but got redirected to frontend page. |
Can you please combine the if statements as suggested? |
This code is in production. |
|
|
@kiatng cant login to admin with that change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements custom admin URL functionality to enhance security by allowing admin interfaces to be accessed via a separate host/domain. The feature enables blocking frontend access to the admin interface when a custom admin URL is configured.
- Adds logic to check and enforce custom admin URL restrictions
- Implements URL replacement for admin stores when custom admin URL is configured
- Fixes an unrelated issue with error directory path validation
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
errors/processor.php | Fixes path reference for error directory validation |
app/code/core/Mage/Core/Model/Store.php | Replaces base URLs with custom admin URL for admin stores |
app/code/core/Mage/Core/Controller/Varien/Router/Admin.php | Blocks admin access when request doesn't match custom admin URL |
app/code/core/Mage/Adminhtml/Helper/Data.php | Adds helper method to retrieve custom admin URL configuration |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
@sreichel To test in ddev: .ddev/config.yaml: additional_hostnames:
- admin The admin URL is: https://admin.ddev.site Configure it with: DELETE FROM core_config_data WHERE path IN ('admin/url/use_custom', 'admin/url/custom');
INSERT INTO core_config_data (scope, scope_id, path, value) VALUES
('default', 0, 'admin/url/use_custom', '1'),
('default', 0, 'admin/url/custom', 'https://admin.ddev.site'); AI has opinions on my implementation, I will investigate them, so I put this on draft first. |
AI is correct! It is bad that str_contains() exposes a security vulnerability, "https://example.com/admin" would be able to access the admin panel because the host "example.com" may be contains in the admin URL "https://admin.example.com/". Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
I am quite happy about this PR, it's nice to increase security up a notch. Please test in real server as well as in DDEV. |
Please retry analysis of this Pull-Request directly on SonarQube Cloud |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works.
Description (*)
Ref #1209 (comment), where I was trying to make use of the nginx config for admin without the use of caddy. For this, I needed the ability to have a custom admin URL, which is configurable here:
However, Custom Admin URL is not implemented. This PR is my attempt to complete the implementation.
When Custom Admin URL is used, frontend access to admin is forbidden in the function
match()
in app/code/core/Mage/Core/Controller/Varien/Router/Admin.php. This is independent of server config, which provides an alternate way:magento-lts/dev/openmage/nginx-frontend.conf
Lines 150 to 154 in 5a95706
Related Pull Requests
PR #1209
Manual testing scenarios (*)
For testing in DDEV, see this comment.

2. Go to admin > System > Configuration > Advanced / Admin > Admin Base URL
Set the Custom Admin URL and save:
If skip the above step in admin panel, you can update the tablecore_config_data
directly:Do not update the table directly, use the admin panel to configure the custom admin URL. The following is only for reference.
www.example.com/adminFrontName
should return 404 page not found.Questions or comments
I am not sure if this is the best way to implement the custom admin URL. Collab welcome.With AI help, I think the implementation now is good.Possible issue for API in 3rd-party code because of
magento-lts/api.php
Line 38 in 5496d8a
As can be seen above, API is admin store, and if there is a
Mage::getUrl()
in the response params, the URL will not be accessible. There is noMage::getUrl()
in the API core, but may be present in 3rd-party code/modules.This PR does not test for the custom path, the suffix in the admin URL.