Add the missing protection headers
Three lines that protect.
Another website can show yours inside its own page and trick people into clicking. A browser can also run an uploaded file as a program. A few lines stop both.
Before you start
- Whoever runs your server or hosting can do this. Send them this page.
- Copy the settings file to another folder, such as your home folder, before you change it. Putting it back is the way to undo this.
- Run the check below first, and add only the lines that are missing.
- Does another site show your pages on purpose, such as a booking window or a partner portal? Write its address after 'self', or it will stop working.
The steps
Put these in the site's block for port 443, with a copy of any add_header lines from nginx.conf, or they stop working. Repeat them in any location block that has its own.
add_header X-Content-Type-Options nosniff always;
add_header X-Frame-Options SAMEORIGIN always;
add_header Content-Security-Policy "frame-ancestors 'self'" always;Then check the settings and reload.
sudo nginx -t && sudo nginx -s reloadIf it shows an error, or the site stops, put the saved copy back and restart the server program at once.
Put these in the site's settings for port 443. On Debian and Ubuntu, first run: sudo a2enmod headers
Header always set X-Content-Type-Options "nosniff"
Header always set X-Frame-Options "SAMEORIGIN"
Header always add Content-Security-Policy "frame-ancestors 'self'"Then check the settings and reload.
sudo apachectl configtest && sudo apachectl gracefulIf it shows an error, or the site stops, put the saved copy back and restart the server program at once.
Put these in the frontend.
http-after-response set-header X-Content-Type-Options nosniff
http-after-response set-header X-Frame-Options SAMEORIGIN
http-after-response add-header Content-Security-Policy "frame-ancestors 'self'"Then check the settings and reload.
sudo haproxy -c -f /etc/haproxy/haproxy.cfg && sudo systemctl reload haproxyIf it shows an error, or the site stops, put the saved copy back and restart the server program at once.
Put this in the site.
header {
X-Content-Type-Options nosniff
X-Frame-Options SAMEORIGIN
Content-Security-Policy "frame-ancestors 'self'"
}Then check the settings and reload.
sudo systemctl reload caddyIf it shows an error, or the site stops, put the saved copy back and restart the server program at once.
Select the site in IIS Manager, open HTTP Response Headers, and add each name with its value.
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
Content-Security-Policy: frame-ancestors 'self'Under Rules, create a response header transform rule for all requests, choose Set static, and add each name with its value.
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
Content-Security-Policy: frame-ancestors 'self'CloudFront: create your own response headers policy. The ready-made one also makes browsers insist on https for a year. Load balancer: add the headers under the HTTPS listener's Attributes.
Add these to the site's .htaccess file.
<IfModule mod_headers.c>
Header always set X-Content-Type-Options "nosniff"
Header always set X-Frame-Options "SAMEORIGIN"
Header always add Content-Security-Policy "frame-ancestors 'self'"
</IfModule>Open Apache & nginx Settings, find Additional headers, choose a custom value and paste these.
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
Content-Security-Policy: frame-ancestors 'self'Check that it worked
curl -sI https://example.com/All three lines should appear, once each.
To undo it
Put the saved copy of the settings back, then check and reload again.
Common mistakes
- Replacing a Content-Security-Policy the site already sends. Add frame-ancestors to the existing one instead.
- Sending the same line twice, from the server and from the website itself.