Header guide · X-Content-Type-Options

X-Content-Type-Options: nosniff and the MIME types it breaks

X-Content-Type-Options: nosniff stops browsers from guessing content types, so files cannot run as scripts or styles. What it blocks and the MIME types to fix first.

With X-Content-Type-Options: nosniff, app.js served as application/javascript runs in the page, while avatar.png served as image/png and data.json served as application/json are refused as scripts.LOADED AS SCRIPTNOSNIFFYOUR PAGEapp.jsapplication/javascriptavatar.pngimage/pngdata.jsonapplication/json
nosniff — only a JavaScript type runs as a script.
In short5 points
  • X-Content-Type-Options: nosniff tells the browser to trust the Content-Type you send instead of guessing. It has one valid value.
  • With it, a response loaded as a script must have a JavaScript type, and a stylesheet must be text/css. Uploaded images, JSON or text files can no longer run as scripts.
  • It breaks scripts served with the wrong type, such as text/plain or application/octet-stream. Check the Content-Type of your JavaScript and CSS files before you deploy it.
  • Send it on every response, static files included. Browsers read only the first value: nosniff, foo works, foo, nosniff does not.
  • It is worth 10 points in WebSec0: nosniff as the first value passes, anything else fails, as browsers ignore it.

What is X-Content-Type-Options?

X-Content-Type-Options is an HTTP response header whose only value, nosniff, tells the browser to trust the Content-Type you send instead of guessing the type from the content. A response loaded as a script must then have a JavaScript type, a stylesheet must be text/css, and a page sent without a type is not rendered as HTML.

HTTP
X-Content-Type-Options: nosniff

Every current browser supports it. It is also one of the most common security headers: in Scott Helme’s June 2026 crawl, 311,659 of the 819,002 top sites that responded sent it (about 38%).

What MIME sniffing is and why it is risky

Browsers were built to cope with servers that send wrong or missing types. When the declared type does not fit, they inspect the bytes and guess. That guess turns harmless files into active content:

Attack Without nosniff With nosniff
A user uploads avatar.png that contains JavaScript, and injected markup loads it with <script src> The file runs as a script Blocked: image/png is not a JavaScript type
Another site loads your JSON API with <script src> to read data from it The browser tries to run it Blocked: application/json is not a JavaScript type
An uploaded file is served without a Content-Type and contains HTML Rendered as an HTML page, scripts included Shown as text

The first case matters even with a Content-Security-Policy: script-src 'self' allows any URL on your origin, including uploaded files. nosniff makes sure only files served as JavaScript can run.

What nosniff changes

The Fetch standard applies nosniff to two kinds of requests only: scripts and stylesheets. Images are excluded, because blocking them broke existing sites. For pages, the MIME Sniffing standard stops the browser from guessing HTML when no type is given. What we saw in Chrome 152:

Response Loaded as Without nosniff With nosniff
JavaScript as application/javascript <script> Runs Runs
JavaScript as text/plain <script> Runs Blocked
JavaScript as application/octet-stream <script> Runs Blocked
JavaScript as application/json <script> Runs Blocked
JavaScript as text/html <script> Runs Blocked
CSS as text/plain <link rel="stylesheet"> Ignored Ignored
HTML with no Content-Type Page Rendered as HTML Shown as text
HTML as text/plain Page Shown as text Shown as text

When it blocks a script, Chrome logs: “Refused to execute script from ‘…’ because its MIME type (‘text/plain’) is not executable, and strict MIME type checking is enabled.”

Two cases are strict even without the header. Chrome already ignores a stylesheet served as text/plain in standards mode, and module scripts (<script type="module">) must always have a JavaScript type.

What it can break

nosniff only breaks responses whose type is already wrong. Before deploying it, check the Content-Type of every JavaScript and CSS file:

Shell
curl -sI https://example.com/assets/app.js | grep -i "^content-type"
curl -sI https://example.com/assets/app.css | grep -i "^content-type"
Content Type it needs Common mistakes
JavaScript (.js, .mjs, .cjs) text/javascript or application/javascript .mjs missing from the server’s MIME table and served as application/octet-stream
CSS text/css Served as text/plain by a misconfigured server
JSONP responses loaded with <script> A JavaScript type Served as application/json
Files from object storage or a CDN The real type, set when uploading Stored with a generic binary type
Scripts generated by your application A JavaScript type A generic type such as text/html or text/plain

text/javascript is the type RFC 9239 recommends. Browsers accept the older application/javascript as well. Images, fonts, video and downloads are not affected.

The value

The header has a single valid value, nosniff, in any case. Browsers split the header on commas, across several headers too, and only look at the first value. What we saw in Chrome 152, with a script served as text/plain:

Header sent nosniff applied?
nosniff Yes
NoSniff Yes
nosniff, foo Yes
nosniff, twice in two headers Yes
foo, nosniff No
"nosniff" with quotes No

Where to send the header

  • On every response. It matters most on scripts, stylesheets, user-uploaded files and API responses, which are exactly the responses a page-only setup misses.
  • On static file locations. Web server blocks that add caching headers to /assets/ often drop the security headers at the same time.
  • On error pages too. They are often served by a different rule and miss headers set for normal responses.
  • Once. Two nosniff headers are harmless, but a stray value before it disables it. Pick one owner, the application or the web server.

Roll it out

  1. List your script and style URLs, including CDN, upload and API paths.
  2. Check their Content-Type with curl -sI and fix any that is not a JavaScript type or text/css.
  3. Make sure uploads are served with a fixed type, and with Content-Disposition: attachment when users should download them.
  4. Add X-Content-Type-Options: nosniff to every response.
  5. Open your pages with the browser console and look for “Refused to execute script” or “Refused to apply style” errors.
  6. Scan the site with WebSec0 to confirm the header is served.

Common mistakes

  • Adding it only to HTML pages. It protects scripts, styles and uploads; the header must be on those responses.
  • Deploying it before fixing types. A script served as text/plain or application/octet-stream stops running.
  • Writing another value. X-Content-Type-Options: none or sniff is ignored. Only nosniff exists.
  • Quoting the value. "nosniff" with quotes is ignored.
  • Relying on it for uploads alone. It stops uploads from running as scripts, but serve them from a separate domain or as attachments as well.
  • Assuming it covers images. It does not change how images are handled.

How WebSec0 grades X-Content-Type-Options

X-Content-Type-Options is worth 10 of the 100 points in the WebSec0 headers grade. The scanner fetches your page and reads the header the way browsers do: it splits every X-Content-Type-Options header on commas and looks at the first value.

What WebSec0 sees Status Points
No X-Content-Type-Options header Fail 0 / 10
A first value other than nosniff, which browsers ignore Fail 0 / 10
nosniff as the first value, in any case Pass 10 / 10

A few details follow from how the check works:

  • There is no warning. nosniff is the only valid value, so any other value protects nothing. foo, nosniff and a quoted "nosniff" fail.
  • Duplicates are fine. nosniff, nosniff, in one header or two, passes.
  • Only your page is checked. WebSec0 does not fetch your scripts and stylesheets, which need the header as much as the page. Check them with curl.

Step by step

Configure it on your server

Setting up every header at once? Read all security headers on Apache, all security headers on Caddy, all security headers on Nginx, all security headers on Traefik.

Questions

Frequently asked questions

What does X-Content-Type-Options: nosniff do?

It tells the browser not to guess a response's type from its content. A file loaded with <script> must then be served with a JavaScript type, a stylesheet with text/css, and a page without a Content-Type is not rendered as HTML.

What is MIME sniffing?

When a response has no Content-Type, or one that does not match its use, browsers can inspect the bytes and guess the type. That guess lets a file uploaded as an image or text run as a script or render as HTML.

Is X-Content-Type-Options still needed in 2026?

Yes. In our test in Chrome 152, a script served as text/plain, application/octet-stream, application/json or text/html still ran without the header, and was blocked with it.

What can nosniff break?

JavaScript or CSS served with the wrong type: a missing MIME mapping, such as .mjs files in the default Nginx configuration, a script served as text/plain, or files stored without a type. Fix the types before deploying the header.

Does nosniff affect images?

No. The Fetch standard limits the blocking to scripts and stylesheets, because applying it to images was not compatible with existing sites.

Are there other values than nosniff?

No. nosniff is the only value, in any case. Browsers look at the first value of the header, so nosniff, nosniff works but foo, nosniff or a quoted "nosniff" is ignored.

Which Content-Type should JavaScript use?

text/javascript, which RFC 9239 recommends. application/javascript is still accepted by browsers. Both pass the nosniff check.

References

Sources

About the author

Portrait of Joshua Martinelle

Security engineer at Tenable

Security engineer at Tenable and web security researcher. He has disclosed more than 60 CVEs since 2020 and builds WebSec0.

Verify the change

Deployed it? Check it.

WebSec0 grades your TLS setup and security headers, including X-Content-Type-Options, in a few seconds. Free, no account.

Scan your site