Check 03 · MIME
Content-type sniffing
X-Content-Type-Options
X-Content-Type-Options: nosniff tells browsers to use the content type you declare instead of guessing it.
What it does
Every response says what it contains in its Content-Type header. Some browsers have long second-guessed that label and looked at the content itself (content sniffing). A file uploaded as an image or plain text could then be treated as HTML or a script.
With nosniff, browsers stick to the declared type. They also refuse to run a script, or apply a stylesheet, that arrives with a type that doesn't match.
How we score it
| 20 | The effective value is nosniff (trimmed, any letter case). |
|---|---|
| 0 | Missing or any other value. |
All five checks and the grade scale: How grading works.
Examples
- X-Content-Type-Options: nosniff
20 / 20 · Strong The only value the header has.
- X-Content-Type-Options: NoSniff
20 / 20 · Strong Letter case doesn't matter.
- X-Content-Type-Options: sniff
0 / 20 · Weak Not a value browsers know, so the header has no effect.
- No header.
0 / 20 · Missing Without the header, browsers may guess.
How to set it
Send the header on every response, including files and uploads.
Check that scripts are served as text/javascript and stylesheets as text/css. A file served as text/plain that used to work will be refused once nosniff is on.
Nginx
Put this in the server block. A location block with its own add_header lines doesn’t inherit these, so repeat them there.
add_header X-Content-Type-Options "nosniff" always;Apache
In the virtual host or .htaccess. Needs mod_headers (on Debian and Ubuntu: a2enmod headers).
Header always set X-Content-Type-Options "nosniff"Caddy
Inside your site block in the Caddyfile.
header X-Content-Type-Options "nosniff"Cloudflare
Rules → Create rule → Response Header Transform Rule. Apply to all incoming requests, choose “Set static”, and enter each header below.
Header name: X-Content-Type-Options
Value: nosniffCommon mistakes
- Adding nosniff to HTML pages only. Uploaded files and downloads are where sniffing matters most.
- Serving scripts from storage that labels everything as a generic binary type. They stop loading once nosniff is on.