如何隐藏您的Magento 2版本

拥有易于发现的特定版本的软件可以使黑客的工作更加轻松,并允许自动抓取工具收集具有特定软件版本的URL数据库,这些数据库可以在发现安全漏洞进行攻击时使用。当然,隐藏Magento版本不足以保护商店的安全,但这只是一个简单的步骤,就像更改管理URL可以使商店更安全一样。

在Magento 2中,Magento_Version模块允许通过GET请求检索Magento版本和版本。它由一个具有以下路线的简单控制器动作组成:

magento_version/index/index

此操作获取所需的信息并呈现:

# Magento\Version\Controller\Index\Index

public function execute()
    {
        $versionParts = explode('.', $this->productMetadata->getVersion());
        if (!isset($versionParts[0]) || !isset($versionParts[1])) {
            return ; // Major and minor version are not set - return empty response
        }
        $majorMinorVersion = $versionParts[0] . '.' . $versionParts[1];
        $this->getResponse()->setBody(
            $this->productMetadata->getName() . '/' .
            $majorMinorVersion . ' (' .
            $this->productMetadata->getEdition() . ')'
        );
    }

要检查模块是否在您的商店中处于活动状态,请导航至上述路线:

http://base-url-of-your-store.com/magento_version

例如:在浏览器输入下面网址。

如果模块处于活动状态,您将看到Magento 2实例的版本,如以下示例所示:

Magento/2.3 (Community)

平台的版本和类型之类的信息可以在发现潜在漏洞时帮助黑客。这就是为什么我们建议您在商店中停用此模块的原因。

为此,请通过SSH导航到您的Magento实例根目录,然后运行以下命令:

php bin/magento module:disable Magento_Version

您将获得以下内容:

The following modules have been disabled:
- Magento_Version

Cache cleared successfully.
Generated classes cleared successfully. Please run the 'setup:di:compile' command to generate classes.
Info: Some modules might require static view files to be cleared. To do this, run 'module:disable' with the --clear-static-content option to clear them.

现在检查结果。转到URL:

http://xx.com//magento_version

如果一切正确,您将获得404页面,这对我们有好处: