MENTECHLet’s talkالعربية
Menu

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 reload

If it shows an error, or the site stops, put the saved copy back and restart the server program at once.

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.
Have us fix it for you
CallWhatsAppLet’s talk