Joomla 4 and 5 ship with a built-in HSTS toggle in Global Configuration but rely on the server (typically Apache via .htaccess) for the other five security headers our Security Audit checks. This guide walks through every fix: enabling Joomla's HSTS, adding the rest via .htaccess, hardening session cookies, and publishing security.txt. Tested against Joomla 5.1 on Apache 2.4. For WordPress, see the WordPress variant; for the full finding catalogue, see Security Audit Fixes.
Joomla 4+ has a native HSTS feature you should use before adding HSTS via .htaccess — it integrates with Joomla's URL routing.
Joomla doesn't manage CSP, X-Frame-Options, X-Content-Type-Options, Referrer-Policy or Permissions-Policy natively. Add them to the root .htaccess:
htaccess.txt (template) and .htaccess (active file). If .htaccess is missing, rename htaccess.txt to .htaccess first..htaccess: <IfModule mod_headers.c> Header always set X-Frame-Options "SAMEORIGIN" Header always set X-Content-Type-Options "nosniff" Header always set Referrer-Policy "strict-origin-when-cross-origin" Header always set Permissions-Policy "geolocation=(), microphone=(), camera=()" Header always set Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; frame-ancestors 'self'" </IfModule>
'unsafe-inline' for script-src and style-src — restrict this once you've identified all extensions that need it.Joomla's session cookies need the Secure and HttpOnly flags. SameSite needs configuration in Global Configuration.
Lax (recommended default). Save..well-known/security.txt in the Joomla root: Contact: mailto:security@yourdomain.com Expires: 2027-05-18T00:00:00.000Z Preferred-Languages: en Canonical: https://yourdomain.com/.well-known/security.txtAdd to
.htaccess: <Files "security.txt"> ForceType text/plain </Files>
curl -sI https://yourdomain.com/ | grep -iE "strict-transport|x-frame|x-content|referrer|permissions|content-security"All six should appear. Then re-run the Security Audit.
Verify every header, TLS protocol and security.txt with a fresh scan.
Run Security Audit →