How to harden PrestaShop security?

Summary
This guide outlines a comprehensive security strategy for securing PrestaShop installations by setting proper file permissions, configuring Apache and Nginx server blocks, and implementing additional security recommendations. The main focus is on preventing unauthorized access to sensitive files and directories through strict permission settings and access control mechanisms. Key points include avoiding global 777 permissions for regular folders and static files, ensuring only specific writeable directories are accessible (like /img/, /upload/), keeping core folders read-only, removing unnecessary write permissions after setup, and blocking PHP execution in upload and image directories. The guide also emphasizes the importance of securing sensitive configuration files and disabling dangerous PHP functions if supported by the hosting environment. For Nginx servers, it recommends disabling directory listing, denying access to sensitive directories, preventing PHP execution in specific folders, and restricting direct access to standalone PHP files. Additional recommendations include renaming or restricting backend access, using strong admin passwords with two-factor authentication, removing unused modules and themes, checking logs regularly, and backing up before making changes.
Admin
Moderating
Donor Member
Master Member
Elite Member
Active Member
Beigetreten
Mai 31, 2020
Nachrichten
2,980
Reaktionswert
1,693
This guide follows the same hardening strategy: set proper file permissions first, then apply webserver rules to block unauthorized access, prevent PHP execution inside upload folders and protect sensitive configuration files.

1. File & Folder Permissions​

Never use global 777 permissions.

  • Regular folders: 755
  • Static files (php, tpl, twig, css, js): 644
  • Folders requiring write access (only these):/img/, /upload/, /var/cache/, /var/logs/, /var/uploads/Set these writable directories to 755. If your hosting needs group write permission, use 775.
  • Core folders to keep read-only: /src/, /controllers/, /classes/, /modules/, /themes/
  • Security cleanup: Delete /install folder completely after finishing installation.
Key permission principle:Upload directories should only store images/assets, never allow PHP script execution inside them. Remove write permission from PHP source files once setup is finished. Clean leftover files from old modules/themes.

2. Apache (.htaccess, site root)​

  1. Disable directory listing
Options -Indexes
  1. Block direct access to sensitive core folders
<DirectoryMatch "^/(src|classes|controllers|config|translations)">
Require all denied
</DirectoryMatch>
  1. Block PHP execution inside image and upload directories
<Directory "/img">
<FilesMatch "\.(php|phtml|php5|twig)$">
Require all denied
</FilesMatch>
</Directory>
<Directory "/upload">
<FilesMatch "\.(php|phtml|php5|twig)$">
Require all denied
</FilesMatch>
</Directory>
  1. Protect configuration files
<Files "settings.inc.php">
Require all denied
</Files>
<Files "parameters.php">
Require all denied
</Files>
  1. Disable dangerous PHP functions (if host supports php_value)
php_value disable_functions eval,passthru,system,shell_exec,popen

3. Nginx server block rules​

  1. Disable directory listing
  1. Deny access to sensitive core directories
location ~ ^/(src|classes|controllers|config|translations)/ {
deny all;
}
  1. Prevent PHP execution in img and upload folders
location ~ ^/(img|upload)/.*\.(php|phtml|twig)$ {
return 403;
}
  1. Block access to sensitive config files
location ~ /(settings\.inc|parameters)\.php$ {
return 403;
}
  1. Restrict direct access to standalone PHP files
location ~* ^(?!/index\.php).*\.php$ {
return 403;
}
  1. Limit upload size
client_max_body_size 32M;

Additional PrestaShop security recommendations​

  1. Rename or restrict backend access. Restrict admin access by IP in webserver config if you have static IP.
  2. Use strong admin passwords. Enable two-factor authentication inside PrestaShop back office.
  3. Remove unused modules and themes, delete leftover override files.
  4. Check logs regularly under /var/logs/.
  5. Always backup database and files before installing new modules or themes.
  6. Test webserver rules on staging first. Misconfigured rules may break frontend or backend access.
Important reminder Permissions and webserver rules lower attack surface, but cannot fully protect you from malicious third-party modules. Always test extensions on staging before deploying on production.

If you run into 403 errors after applying these rules, create a support thread with your webserver type and configuration.
 
Zuletzt bearbeitet:
Trending Resources
Zurück
Oben