How to improve security for your Magento 1.x site?

Summary
Magento 1.x is no longer receiving official security patches, so hardening the web server configuration is crucial for reducing attack surfaces. The main thread discusses implementing Apache or Nginx server rules to block direct directory browsing, restrict file upload locations, and prevent direct access to PHP files outside of entry points. For Apache, disabling directory listing in .htaccess blocks visitors from browsing directories. Restricting uploads inside the media folder prevents executable files from running there. Blocking direct access to PHP files except index.php ensures only index.php can be accessed directly. Nginx server block rules include disabling directory listings and blocking direct access to PHP files except index.php, while also preventing execution in the media folder. Additionally, restricting upload paths so that only /media accepts uploaded assets is recommended. Important notes emphasize testing these changes on a staging environment first and suggest migrating to OpenMage LTS for community security fixes. Regular backups are also advised, along with IP restrictions for admin panel access and strong passwords. After applying server rules, it's crucial to test the site frontend, checkout process, and admin login to ensure no unintended 403 blocks occur.
Admin
Moderating
Donor Member
Master Member
Elite Member
Active Member
Beigetreten
Mai 31, 2020
Nachrichten
2,980
Reaktionswert
1,693
Magento 1.x no longer gets official security patches, so hardening your web server configuration is critical to reduce attack surfaces. You can implement rules for Apache or Nginx to block direct directory browsing, restrict file upload locations, and prevent direct access to PHP files outside of entry points.

Apache configuration (.htaccess):

  1. Disable directory listing for all foldersAdd this rule to your root .htaccess to stop visitors browsing your directories:
Options -Indexes
  1. Restrict file uploads only inside media folderBlock upload scripts and disallow file uploads outside /media. Prevent executable files from running inside media directory:
<FilesMatch "\.(php|phtml|php3|php4)$">
Require all denied
</FilesMatch>
<Directory "/media">
<FilesMatch "\.(php|phtml|php3|php4)$">
Require all denied
</FilesMatch>
</Directory>
  1. Block direct access to PHP files except index.phpPrevent accessing any standalone PHP files directly, only allow index.php as entry point:
RewriteCond %{REQUEST_FILENAME} !index.php
RewriteRule ^.*\.php$ - [R=403,L]
Nginx server block rules:

  1. Disable directory listing
  1. Deny direct access to PHP files except index.php
location ~* ^(?!/index\.php).*\.php$ {
return 403;
}
  1. Block PHP execution inside media folder
location ~* ^/media/.*\.php$ {
return 403;
}
  1. Restrict upload paths, block writable folders executionOnly /media should accept uploaded assets; block uploads in app, var, lib and other core directories.
location ~ ^/(app|lib|var|includes|pkginfo)/ {
deny all;
}
Important notes:Always test these rules on staging first before applying to live sites. Incorrect webserver rules can break store frontend and admin access.These server rules are supplementary protection only. They cannot fully compensate for outdated core code. We recommend migrating your M1 to OpenMage LTS to receive community security fixes.Keep regular backups, restrict admin panel access by IP if possible, use strong admin passwords and avoid unknown third-party extensions.

After applying webserver rules, test site frontend, checkout and admin login to confirm no unintended 403 blocks.
 
Trending Resources
Zurück
Oben