Wiki / Security headers

Warning: X-Content-Type-Optionsheader not set

The browser may guess a file's type on its own and, for example, open a text file uploaded by a visitor as an HTML page with scripts. One line, nosniff, turns that off; it matters most for sites where visitors upload files.

What it does not mean. It does not mean the site holds malicious files. If visitors cannot upload anything, the risk here is small.

Aleksandr IzmalkovFacts checked:

In our report
Warning (yellow), category weight 1.0 of 2.0
Time to fix
5 minutes
Can it break things
Rarely: scripts and styles the server sends with the wrong type stop loading

How to fix it

nginx (tested on 1.26.3)

add_header X-Content-Type-Options "nosniff" always;

Apache (tested on 2.4.59, also works in .htaccess)

Header always set X-Content-Type-Options "nosniff"

Cloudflare

SSL/TLS → Edge Certificates → HTTP Strict Transport Security (HSTS) → No-Sniff Header

The switch sits in the same dialog as the HSTS settings.

How to check

curl -sI https://example.com | grep -i x-content-type-options
curl -sI https://example.com/wp-includes/js/jquery/jquery.min.js | grep -i content-type

Expected

x-content-type-options: nosniff
content-type: application/javascript

The second command shows whether scripts are served with a JavaScript type. Replace the path with a script from your own site.

Terminal: a test nginx returns X-Content-Type-Options: nosniff together with the other security headers
A test nginx 1.26.3 with four security headers: they are sent on both the 200 and the 404 response.

What can break

  • If the server sends a .js or .css file as text/plain (it happens with unusual extensions or home-made scripts that serve files), the browser stops loading it. Check Content-Type with the command below.

Possible values

There is one value.

ValueWhat it does
nosniffA script loads only with a JavaScript type, a stylesheet only with text/css. For every other file the browser takes the type from Content-Type and no longer guesses

Sources

Next