How to add the X-Content-Type-Options nosniff header
The missing X-Content-Type-Options warning means your site does not send the line X-Content-Type-Options: nosniff with its pages and files. Adding that one header in your web server, hosting or CDN settings clears it, and it rarely changes how your site looks.
Your website sends a small set of hidden instructions, called HTTP headers, along with every page and file. X-Content-Type-Options is one of them. If a security scan reports it as missing, it means your server is not sending it. The fix is usually a single line of configuration, and it is a low risk change when done carefully.
What the problem is
Every file your site delivers carries a label called Content-Type, for example text/html for a page, image/png for a picture or text/css for a stylesheet. Browsers have a habit of second guessing that label by peeking at the file contents and deciding what it really is. This is called MIME sniffing. It was meant to help with badly configured sites, but it can be abused: a file uploaded as a harmless image or text file can contain script code, and a sniffing browser may run it as a script.
The header X-Content-Type-Options: nosniff tells the browser to trust the label and not guess. nosniff is the only value this header uses.
Visitors never see anything. The only sign of the problem is in a security report, usually worded like "Missing X-Content-Type-Options header" or "X-Content-Type-Options not set".
Why it matters
Be realistic about the size of this one. It is a low severity finding, but it is cheap to fix and it is checked by almost every scanner and audit.
- Security: it closes off one type of attack. It matters most on sites where visitors can upload files or post content, such as forums, membership sites, comment sections and profile pictures.
- Audits and questionnaires: clients, insurers and larger customers sometimes run a header check or send a security questionnaire. A missing header is an easy thing for them to point at.
- Trust: it is invisible to visitors and does not change how pages look or load. Its value is in having a tidy, complete security setup.
It works well alongside related headers, such as the one covered in our guide to a missing X-Frame-Options header.
How to check if your site has it
Three free ways, from easiest to most technical:
- Online checkers. Paste your address into securityheaders.com or the Mozilla Observatory. Both list the headers your site sends and show which are missing.
- Your browser. Open your site, press
F12(or right-click and choose Inspect), open the Network tab and reload the page. Click the first entry, which is your page address, and look under Response Headers forx-content-type-options: nosniff. - The command line. Run the command below and look for the header in the output.
curl -I https://www.example.com
Check a CSS, JavaScript or image file as well as the home page. Different paths can be handled by different rules, so a page may have the header while your uploads folder does not.
How to fix it
The header has to be sent by whatever serves your site: the web server, the hosting platform or a CDN in front of it. Add it once, at the level that covers the whole site, with the value nosniff. Where exactly depends on your setup:
| Where your site runs | Where to look |
|---|---|
| Nginx | The server block in your site config |
| Apache | The virtual host config or the .htaccess file |
| WordPress | A security headers setting, or the server config underneath |
| Cloudflare | Rules, then Transform Rules, then Modify Response Header |
| IIS | web.config, under custom headers |
| Netlify | A _headers file or netlify.toml |
| Vercel | The headers section of vercel.json |
Step by step guides: Nginx, Apache and WordPress. The most common snippets are below.
Nginx, inside the server block:
add_header X-Content-Type-Options "nosniff" always;
Then test and reload with sudo nginx -t followed by sudo systemctl reload nginx. One catch: if a location block has its own add_header lines, the server level ones are not inherited there, so repeat the line in that block.
Apache, in the virtual host or .htaccess (needs the mod_headers module, which most hosts enable):
<IfModule mod_headers.c>
Header always set X-Content-Type-Options "nosniff"
</IfModule>
IIS, in web.config inside system.webServer:
<httpProtocol>
<customHeaders>
<add name="X-Content-Type-Options" value="nosniff" />
</customHeaders>
</httpProtocol>
Netlify, in a file named _headers in your published folder:
/*
X-Content-Type-Options: nosniff
Cloudflare: create a Modify Response Header rule that applies to all incoming requests, choose Set static, enter the header name X-Content-Type-Options and the value nosniff. The menu names change from time to time, so look for response header rules if yours differ.
WordPress: WordPress itself does not have a built in switch for this. On Apache hosting you can add the .htaccess lines above. Many security plugins and some managed hosts also include a headers option. If your host manages the server, ask their support to add it.
Check your file types first
Once nosniff is on, browsers will refuse to run a script or apply a stylesheet if the server labels it with the wrong type. A JavaScript file sent as text/plain will stop working. On a normally configured site this does not happen, but on old or unusual setups it can. After the change, click through your key pages, forms and checkout, and look for broken styling or features. If something breaks, the file is being sent with the wrong Content-Type, and fixing that label is the right answer, not removing the header.
How to confirm the fix worked
- Clear your cache or open a private window, since old responses can be cached.
- Run
curl -Iagain, or reload with the Network tab open, and confirmx-content-type-options: nosniffappears on the page and on a CSS or image file. - Rerun the online checker.
- Browse your main pages to make sure nothing looks broken.
If the header still does not show and you use a CDN, check whether the CDN is stripping it or whether an old cached copy is being served. Purge the cache and test again.
How to stop it coming back
The header disappears most often when a server is rebuilt, a host is changed, a config file is overwritten or a CDN rule is removed. Keep the line in the main configuration rather than in a one-off place, write down where you put it, and recheck after any migration or hosting change.
SiteMonday's week 2 OpenVAS security scan looks for this header, among other things, and the written report lists it in the ranked fix list so you can see whether it has returned. Scans only run after you prove you own the site. SiteMonday finds and explains the problem. Making the change is up to you or your developer.
Step by step for your platform
- Missing X-Content-Type-Options header on Nginx
- Missing X-Content-Type-Options header on Apache
- Missing X-Content-Type-Options header on WordPress
- Missing X-Content-Type-Options header on Cloudflare
- Missing X-Content-Type-Options header on IIS
- Missing X-Content-Type-Options header on Netlify
- Missing X-Content-Type-Options header on Vercel
Questions
What does nosniff actually do?
It tells the browser to trust the Content-Type label the server sends and not guess a file's type from its contents. This blocks attacks that rely on a file being treated as something other than what it was labelled.
Can this header break my website?
Rarely. If a script or stylesheet is sent with the wrong Content-Type, browsers will refuse to use it once nosniff is on. The right fix is to correct that file's type, so test your main pages after adding the header.
Is there any value other than nosniff?
No. `nosniff` is the only value browsers recognise for this header, so you can copy it exactly as written.
Will it make my site rank higher or load faster?
It is a security setting and does not change how pages look or load. Its value is in closing off a type of attack and passing security checks.
Do I need to add it to every page?
You should send it on all responses, including images, scripts and downloads. Setting it once at server, host or CDN level covers everything.
I use shared hosting and cannot edit server files. What can I do?
Try the `.htaccess` method if your host uses Apache, or look for a security headers option in your control panel or a security plugin. If neither is available, ask your host's support to add it.