Opens in a new tab

X-Content-Type-Options: nosniff — stop browsers guessing file types

X-Content-Type-Options: nosniff tells the browser to believe the Content-Type your server declares instead of guessing from the file’s contents. With it, a file served as text or an upload served as an image cannot be run as a script. It has one value, costs one line, and breaks nothing that is served with the right type.

Defined inThe WHATWG Fetch Standard
Only valuenosniff
BlocksScripts and styles whose declared type is wrong
Browser supportEvery current browser

Check X-Content-Type-Options on your site

Enter a domain: we fetch its homepage and read every security header, this one first.

What it does

When a response has no Content-Type, or one the browser doubts, browsers may “sniff” — guess the type from the bytes. That is how a file uploaded as an image, or served as plain text, can end up running as a script. nosniff switches the guessing off.

With nosniff, a request for a script is blocked unless the response is a JavaScript type, and a request for a stylesheet unless it is text/css; every other response is treated exactly as declared, so HTML served as text/plain is shown as text. Images are deliberately not checked.

Directives and values

Directive or valueWhat it does
nosniffThe only value. Browsers read just the first value if the header is sent more than once.

What to send

X-Content-Type-Options: nosniff

Make sure scripts are served as JavaScript and stylesheets as text/css first — with nosniff, a wrong type means the file is blocked rather than guessed. For files users upload, OWASP adds Content-Disposition: attachment.

How to set it

Apache

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

In the virtual host or .htaccess; needs mod_headers (and AllowOverride FileInfo for .htaccess). always also covers error pages and redirects, which plain Header set skips.

nginx

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

In the server block. A location with any add_header of its own drops every add_header from the server block — repeat them there, or from nginx 1.29.3 use add_header_inherit merge;.

IIS (web.config)

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

Caddy

header X-Content-Type-Options "nosniff"

Cloudflare

Rules → Overview → Create rule → Response Header Transform Rule
Set static — header name: X-Content-Type-Options — value: nosniff

On every plan, for records that are proxied through Cloudflare. Set replaces the header if your server already sends one.

WordPress

add_action( 'send_headers', function () {
	header( 'X-Content-Type-Options: nosniff' );
} );

In a small plugin or the theme’s functions.php. PHP only runs for pages WordPress builds, so images, scripts and other static files do not get the header — set it at the server or CDN to cover everything.

Common mistakes

  • Serving JavaScript or CSS with a wrong Content-Type such as text/plain — with nosniff the browser refuses it.
  • Any value other than nosniff, or another value sent first by a duplicate header.
  • Treating the header as a substitute for correct Content-Type headers — the two go together.

What we recommend

Send it on every response. Cloudflare’s “Add security headers” managed transform includes it, if you use Cloudflare.

Questions

Can nosniff break my site?

Only where a script or stylesheet is served with the wrong Content-Type — which is worth fixing anyway. Check the browser console after adding it: a blocked file is reported there.

Sources

Checked on 25 September 2026 against these official sources:

Know when a header disappears

Add your domain and we scan it on a schedule — security headers, certificate, HTTPS, DNS and email — and email you when a security header is removed, a certificate changes or HTTPS stops redirecting. Free for your first domain.

Create a free account