X-Content-Type-Options Header Missing: Add nosniff

, by xura.tools team

TL;DR: Add this header to every response:

X-Content-Type-Options: nosniff

nosniff is the only valid value. Before you turn it on, make sure your server sends the right Content-Type for JavaScript and CSS, or those files will stop loading. Check your site with our security headers tool.

What the warning means

ZAP reports it as "X-Content-Type-Options Header Missing". Other scanners say "content type options missing" or similar. It means your response doesn't include X-Content-Type-Options: nosniff.

Every response has a Content-Type header, like text/html or image/png. Browsers used to not trust it fully. If a file looked like HTML, some browsers would treat it as HTML even when the server said text/plain. This guessing is called MIME sniffing.

What nosniff means

nosniff tells the browser: use the Content-Type I sent, don't guess. MDN lists two effects:

  1. Scripts and styles are checked. If a <script> loads a file whose type is not a JavaScript MIME type, the browser blocks it. Same for a stylesheet that isn't text/css.
  2. No guessing for everything else. A file sent as text/plain stays plain text, even if it has HTML inside. The browser won't render it as a page.

The real risk

The classic attack: your site lets users upload files. Someone uploads a file that is actually HTML with script inside, and your server sends it as text/plain or image/jpeg. Without nosniff, a browser might sniff it, decide it's HTML and run the script on your domain. MDN describes this case directly: nosniff "prevents XSS-attacks where user-uploaded content is executed as an HTML document".

If you don't accept uploads and serve correct types, the risk is small. ZAP rates this finding as Low. But the header costs nothing, so add it.

Check your Content-Type first

This is the one way nosniff can break a site. If your server sends app.js as text/plain or application/octet-stream, the browser will refuse to run it once nosniff is on.

curl -sI https://example.com/assets/app.js | grep -i content-type
curl -sI https://example.com/assets/style.css | grep -i content-type

You want text/javascript (or application/javascript) and text/css. On nginx, make sure include mime.types; is in your http block. Most default configs have it, but its easy to lose when you copy a minimal config from somewhere.

How to add it on your server

nginx

server {
    listen 443 ssl;
    server_name example.com;

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

Use always so it also goes out on 404 and 500 responses. And remember nginx's inheritance rule: add_header lines are inherited from the parent block only if the current block has none. One add_header in a location wipes out the server-level ones there. Repeat them, use an include snippet, or on nginx 1.29.3+ use add_header_inherit merge; (nginx docs).

Apache (.htaccess)

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

Needs mod_headers (a2enmod headers) and AllowOverride FileInfo.

Caddy

example.com {
    header X-Content-Type-Options "nosniff"
    file_server
}

IIS (web.config)

<configuration>
  <system.webServer>
    <httpProtocol>
      <customHeaders>
        <add name="X-Content-Type-Options" value="nosniff" />
      </customHeaders>
    </httpProtocol>
  </system.webServer>
</configuration>

IIS uses its MIME map for static files. If you serve .mjs or other newer file types, check they have the right type in MIME Types in IIS Manager.

Cloudflare (Transform Rules / _headers for Pages)

Easiest: Cloudflare's HSTS settings page (SSL/TLS > Edge Certificates) has a No-Sniff Header option that sends X-Content-Type-Options: nosniff. The Add security headers managed transform also sets it.

Or make a rule: Rules > Overview > Create rule > Response Header Transform Rule, Set static, name X-Content-Type-Options, value nosniff, Deploy.

On Cloudflare Pages, add _headers to your build output:

/*
  X-Content-Type-Options: nosniff

Next.js (next.config.js headers())

// next.config.js
module.exports = {
  async headers() {
    return [
      {
        source: '/(.*)',
        headers: [{ key: 'X-Content-Type-Options', value: 'nosniff' }],
      },
    ];
  },
};

This is the same header the Next.js docs list in their security headers section.

Express (helmet)

import express from 'express';
import helmet from 'helmet';

const app = express();
app.use(helmet()); // includes X-Content-Type-Options: nosniff

If you only want this one header: app.use(helmet.xContentTypeOptions()). Or without helmet, res.setHeader('X-Content-Type-Options', 'nosniff') in a small middleware.

Spring Boot

Spring Security sends X-Content-Type-Options: nosniff by default. If it's missing, someone turned it off. Look for .contentTypeOptions(c -> c.disable()) or headers.disable() in your security config, and remove it. Without Spring Security, add the header in a servlet filter.

WordPress (plugin-free option)

WordPress has a built-in function that sends this exact header. Hook it to every page in your child theme's functions.php or a file in wp-content/mu-plugins/:

add_action( 'send_headers', 'send_nosniff_header' );

This covers pages PHP renders. Uploaded files and theme assets are usually sent by nginx or Apache directly, so add the header in the server config too. Uploads are where nosniff matters most.

How to check it worked

curl -sI https://example.com | grep -i x-content-type-options

You should see x-content-type-options: nosniff. Test a static file and an upload URL too, not only the home page:

curl -sI https://example.com/wp-content/uploads/some-file.pdf | grep -i x-content-type-options

For a full report, here is our live check for www.mozilla.org, which sends nosniff. Then run your own domain in the security headers tool.

Common mistakes

  1. Wrong value. nosniff only. true, on or no-sniff with a dash don't count.
  2. Header only on HTML pages. Uploads and static files need it most. Set it at the web server, not just in the app.
  3. Wrong Content-Type on JS or CSS. With nosniff, a script sent as text/plain is blocked. Fix the type, don't remove the header.
  4. Missing always on nginx, so error pages go out without it.
  5. Thinking it fixes uploads by itself. It stops sniffing. You still need to check what users upload and ideally serve uploads from a separate domain.

FAQ

What does X-Content-Type-Options nosniff mean?

It tells the browser to trust the Content-Type header and not guess the file type from its content. Scripts and styles with the wrong type get blocked.

What does "content type options missing" mean?

Your server doesn't send X-Content-Type-Options: nosniff. Add the one line for your server from above.

Can nosniff break my site?

Only if your server sends the wrong Content-Type for scripts or stylesheets. Check them with curl -sI before you turn it on.

Is X-Content-Type-Options still needed in modern browsers?

Yes. It's part of the Fetch standard that browsers follow today, and MDN notes security testers usually expect it.

Next, check frame protection with X-Frame-Options and your Referrer-Policy and Permissions-Policy.


Is your site affected? Run the free P-256 check.