Hardening the server
The hardened vhost, file ownership, PHP settings, the firewall, SSH, automatic updates and what the application already does on its own.
What the application does on its own#
Every response carries its security headers from PHP — a Content-Security-Policy with a per-request nonce and no third-party origins, HSTS over HTTPS, X-Frame-Options, Referrer-Policy, Permissions-Policy, X-Content-Type-Options — so the vhost does not repeat them. Cookies are __Host-, Secure, HttpOnly and SameSite=Lax over HTTPS. Every change requires a CSRF token and a matching origin.
The hardened vhost#
docs/nginx-hardened.conf adds what PHP cannot do itself:
- redirects HTTP to HTTPS, TLS 1.2 and 1.3 only;
- refuses dotfiles,
billing-paths.php,_entry.php, editor backups and the HA node channel; - long, immutable caching for
/assets/; - after installation, uncomment the line that refuses
install.php.
Files#
public/andapp/belong to root and are read-only for PHP; onlydata/belongs towww-data, plus the five SEO files (see Installation).data/config.phpis0640anddata/keys/master.keyis0600. The self-check fails if either is readable by others.- Keep nothing else in
public/: no release zip, no database dump, nophpinfo.php, no.gitfolder. The self-check lists such files and fails. - After copying a release,
php app/cli.php security:manifestconfirms that every file arrived unchanged. - Never run
app/tools/mutate.phpon a server that takes payments. It switches checks off in the source while it runs, and refuses an installed tree unless forced.
Behind a proxy or load balancer#
When requests reach PHP through a proxy (webgate, a CDN, a load balancer), tell the application which addresses are proxies, in data/config.php:
'http' => ['verify_tls' => true, 'trusted_proxies' => ['10.0.0.5', '192.0.2.0/24']],
Without it every visitor appears to come from the proxy's address: sign-in throttling then counts everybody together, and API key IP allowlists compare the wrong address. The self-check, run from the page, warns when it sees a forwarded request from an address that is not listed.
PHP#
In /etc/php/8.4/fpm/php.ini:
expose_php = Off
display_errors = Off
allow_url_include = Off
log_errors = On
upload_max_filesize = 16M ; dispute evidence is capped at 5 MB, logos at 512 KB
post_max_size = 20M
memory_limit = 256M
opcache.enable = 1
The system monitor suggests OPcache and FPM pool sizes for your memory, with the commands to apply them.
The machine#
sudo ufw allow OpenSSH && sudo ufw allow 'Nginx Full' && sudo ufw enable
sudo apt install -y unattended-upgrades && sudo dpkg-reconfigure -plow unattended-upgrades
- SSH with keys only (
PasswordAuthentication no), and no root login. - MariaDB listens on localhost only (the Ubuntu default). On a two-server pair, replication runs over the private link described in Two-server redundancy.
- The system monitor shows whether a reboot is required and whether automatic updates are on.