X-Content-Type-Options: nosnifftells the browser to trust theContent-Typeyou 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/plainorapplication/octet-stream. Check theContent-Typeof your JavaScript and CSS files before you deploy it. - Send it on every response, static files included. Browsers read only the first value:
nosniff, fooworks,foo, nosniffdoes not. - It is worth 10 points in WebSec0:
nosniffas 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.
X-Content-Type-Options: nosniffEvery 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:
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
nosniffheaders are harmless, but a stray value before it disables it. Pick one owner, the application or the web server.
Roll it out
- List your script and style URLs, including CDN, upload and API paths.
- Check their
Content-Typewithcurl -sIand fix any that is not a JavaScript type ortext/css. - Make sure uploads are served with a fixed type, and with
Content-Disposition: attachmentwhen users should download them. - Add
X-Content-Type-Options: nosniffto every response. - Open your pages with the browser console and look for “Refused to execute script” or “Refused to apply style” errors.
- 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/plainorapplication/octet-streamstops running. - Writing another value.
X-Content-Type-Options: noneorsniffis ignored. Onlynosniffexists. - 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.
nosniffis the only valid value, so any other value protects nothing.foo, nosniffand 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
Apache
Guide ↗Set X-Content-Type-Options: nosniff on Apache with Header always set, keep it on errors and redirects, and fix files Apache sends without a Content-Type. Tested configs.
Caddy
Guide ↗Set X-Content-Type-Options: nosniff on Caddy with the header directive, check the MIME types file_server sends and type files without an extension. Tested configs.
Nginx
Guide ↗Set X-Content-Type-Options: nosniff on Nginx with add_header and always, keep it on static files, and fix the MIME types it breaks, such as .mjs. Tested configs.
Traefik
Guide ↗Set X-Content-Type-Options: nosniff on Traefik with the contentTypeNosniff option, in labels or a file, and fix the Content-Type your backend sends. Tested configs.
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
- MIME Sniffing StandardWHATWG
- X-Content-Type-Options headerMDN Web Docs
- MIME types (IANA media types)MDN Web Docs
