DECLARE THE TYPE, SKIP THE GUESS

X-Content-Type-Options: nosniff: what MIME sniffing is, what the header blocks, correct Content-Type values and how to fix a missing header

Browsers can guess what a response really is when its declared type looks wrong, and that guess can turn an upload or a data file into something executable. X-Content-Type-Options: nosniff tells the browser to trust the Content-Type you send. This guide explains the mechanism, the right Content-Type values, server configuration for common stacks and how to confirm the fix.

Concept illustration of an ivory ceramic sorting board with shaped slots: a mint-glowing glass piece slides into its matching slot while a small copper gate holds back a piece whose shape does not match its blank tag.
Concept illustration

Every HTTP response carries a Content-Type header that says what it is: an HTML page, a stylesheet, a script, a PNG, a JSON document. Browsers do not always take that label at face value. When it is missing or looks implausible, they may inspect the first bytes and decide for themselves. That guess is called MIME sniffing, and it exists because a lot of the early web was served with wrong or missing types.

Guessing is convenient until the guess turns a harmless file into something the browser executes. The header X-Content-Type-Options: nosniff tells browsers to stop second-guessing and to refuse scripts and stylesheets whose declared type does not match. It is one line of configuration, but it only works well when your Content-Type values are right, so this guide covers both.

If a Sitelemetry scan reported the finding http.header.content-type-options.missing, the response it read either had no X-Content-Type-Options header or had a value other than exactly nosniff. Below you will find what the header does, what it protects against, the Content-Type values to send, configuration for common servers and platforms, what can break, and how to verify the fix. All examples use example.com.

Scope of this guide

This guide covers the X-Content-Type-Options header and the Content-Type values it relies on. Sitelemetry reads the home page response of the site you scan, not every script, stylesheet or upload on your site, and an automated check is not a pentest.

1. What MIME sniffing is

A MIME type (also called a media type) is a label such as text/html, text/css or image/png. The server sends it in the Content-Type header, and the MDN Content-Type reference describes how browsers use it to decide what to do with the bytes: render them as a page, apply them as styles, run them as code or show them as an image.

The WHATWG MIME Sniffing Standard defines when a browser may override that label. The typical triggers are:

  • No Content-Type at all, or a placeholder such as unknown/unknown, application/unknown or */*. The browser then looks at byte patterns, for example an opening <html tag or the signature of a PNG file, and computes a type.
  • A label known to be unreliable. Some older server defaults sent text/plain for almost everything, so the standard includes a rule to check whether such a response is actually binary.
  • Images and media, where the browser checks the signature to pick the right decoder.

Sniffing made the early web more forgiving: a page served with a missing type still rendered. The cost is that the browser, not the site owner, ends up deciding what a response is. If the bytes can be read as more than one thing, the browser's guess may not be what you intended.

2. What nosniff changes in the browser

X-Content-Type-Options has one defined value, nosniff. The MDN reference and the Fetch Standard describe its effects:

  • Scripts must have a JavaScript MIME type. If a response with nosniff is requested as a script (a <script> element, a worker, an imported module) and its type is not a JavaScript type such as text/javascript, the browser blocks it.
  • Stylesheets must be text/css. A response requested as a stylesheet with any other type is blocked.
  • Sniffing no longer upgrades to scriptable types. Under the MIME Sniffing Standard, when nosniff is set and a Content-Type is supplied, the browser uses the supplied type as-is. When no usable type is supplied, it may still sniff, but it will not conclude that the bytes are HTML or another scriptable type.
  • Cross-origin read protection. MDN notes that the header enables Cross-Origin Read Blocking protection for HTML, plain text, JSON and XML responses (SVG excepted), which helps keep such responses away from other sites that try to load them as images, scripts or media.

Browsers check the value case-insensitively and look at the first value if the header is repeated, but the safe form is the one every tool expects: one header, lowercase value.

X-Content-Type-Options: nosniff

The header does not change how a correctly labelled response is handled. A real stylesheet served as text/css works exactly as before; only responses whose label and use disagree are affected.

3. The problems it helps prevent

The OWASP HTTP Headers Cheat Sheet recommends sending nosniff on responses. The situations it guards against usually involve content that you host but do not fully control:

  • User uploads read as HTML. A forum lets people upload attachments and serves them from the main domain. If a file is served without a Content-Type, or with a generic one, and its bytes look like HTML, a browser that sniffs could render it as a page in your site's origin. Script in that page would run with access to your origin, which is a stored cross-site scripting problem. With nosniff, the browser will not settle on HTML for it.
  • Uploads used as scripts. A Content-Security-Policy with script-src 'self' allows any script from your own origin. If someone can upload a file that happens to be valid JavaScript, a page could load it with a <script> tag even though it is labelled image/jpeg or text/plain. nosniff blocks that load because the type is not JavaScript.
  • Data files pulled into other pages. JSON, CSV or text endpoints are meant to be read as data. Without the header, other sites may try to load them as scripts or images; with it, browsers refuse the script load and apply cross-origin read protection to the response.
  • Misconfigured static files. When a build or storage bucket serves files with the wrong type, the header makes the mistake visible as a clear console error instead of letting the browser quietly guess.

None of this replaces proper upload handling. The OWASP File Upload Cheat Sheet recommends validating file types, renaming stored files, setting the Content-Type yourself and serving user content from a separate domain where possible. nosniff is a defence-in-depth layer on top of that, which is why Sitelemetry rates a missing header as low rather than high.

4. Get the Content-Type values right first

Because nosniff makes the browser trust your labels, wrong labels turn from harmless to broken. Check these values before you add the header:

ResourceContent-Type to sendCommon mistake
HTML pagestext/html; charset=utf-8No charset, or no type on pages generated by scripts
JavaScript, including modulestext/javascript (application/javascript is also accepted)text/plain or application/octet-stream from storage buckets; blocked under nosniff
Stylesheetstext/cssAn HTML 404 page returned for a missing CSS file; blocked as a stylesheet
JSON APIsapplication/jsontext/html from frameworks that default to HTML
SVG imagesimage/svg+xmltext/xml or no type
Web fontsfont/woff2, font/woffapplication/octet-stream
WebAssemblyapplication/wasmGeneric binary type, which streaming compilation rejects
User uploadsThe validated real type, or application/octet-stream with Content-Disposition: attachmentThe type the uploader claimed, copied without checking

RFC 9239 made text/javascript the standard type for JavaScript; older server defaults that use application/javascript still work. Most web servers map types from file extensions (nginx uses its mime.types file, Apache uses mod_mime), so the usual gaps are files without extensions, assets uploaded to object storage without metadata, and responses generated by application code.

5. Adding the header on common stacks

Send the header on every response, not only on HTML pages: scripts, stylesheets, API responses and uploads are where it matters most. Pick one layer to own it (web server, application or CDN) so it is not sent twice.

nginx

Use always so error responses carry the header too. An add_header inside a location block replaces the headers inherited from the server block, so repeat it there if that location sets its own headers (nginx headers module).

server {
    listen 443 ssl;
    server_name example.com;
    add_header X-Content-Type-Options "nosniff" always;
}

Apache httpd

With mod_headers enabled, Header always set applies to error responses as well and replaces an existing value of the same name (Apache mod_headers).

<IfModule mod_headers.c>
    Header always set X-Content-Type-Options "nosniff"
</IfModule>

IIS

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

Caddy

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

Node.js and Express

The helmet middleware sets X-Content-Type-Options: nosniff by default. Without it, a small middleware does the same:

app.use((req, res, next) => {
  res.setHeader('X-Content-Type-Options', 'nosniff');
  next();
});

Next.js

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

Static hosts and CDNs

On Netlify, add the header to a _headers file; on Vercel, use the headers array in vercel.json; on Cloudflare, a response header modification rule adds it at the edge. For a Netlify _headers file:

/*
  X-Content-Type-Options: nosniff

On WordPress and other CMS platforms, set it at the web server or CDN rather than in a theme, so static files and uploads get it too.

6. What can break and how to roll out safely

On a site whose types are correct, adding nosniff changes nothing visible. When something does break, it is almost always a script or stylesheet with the wrong label:

  • Assets in object storage. Files uploaded to a bucket without a content type are often served as application/octet-stream or binary/octet-stream. Set the type at upload time or fix the metadata of existing objects.
  • Dynamic scripts. A route that generates JavaScript, such as a configuration file or a tag manager proxy, must set text/javascript explicitly.
  • HTML returned for a missing asset. A single-page app that answers every unknown path with index.html returns text/html for a deleted app.js. Under nosniff it is blocked rather than parsed. The fix is to return a real 404 for missing assets.
  • Legacy JSONP. An endpoint that returns application/json but is loaded through a <script> tag stops working. Serving it as text/javascript restores it; moving to fetch with CORS is the better long-term fix.

A practical rollout: list the hosts that serve your scripts and styles, check their types with the commands in the next section, fix the mislabelled ones, then enable the header on a staging environment and browse the key pages with the console open. Once nothing is refused there, enable it in production and keep watching browser error reports for a few days.

7. How to verify the fix

From a terminal, request the page and print the two headers that matter:

curl -sS -D - -o /dev/null https://example.com/ | grep -i -E '^(content-type|x-content-type-options):'

The expected output contains x-content-type-options: nosniff once and a sensible content-type. Repeat the command for a script, a stylesheet, an API response and an uploaded file, because they are often served by different layers:

curl -sS -D - -o /dev/null https://example.com/assets/app.js
curl -sS -D - -o /dev/null https://example.com/assets/site.css
curl -sS -D - -o /dev/null https://example.com/api/status
curl -sS -D - -o /dev/null https://example.com/does-not-exist

The last request checks that error pages carry the header too. On Windows, call curl.exe, use -o NUL and filter with findstr /i.

In the browser, open DevTools, select a request in the Network panel and read its response headers. In the Console, Chrome reports blocked resources with messages such as Refused to execute script from … because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled, or Refused to apply style from … because its MIME type ('text/html') is not a supported stylesheet MIME type. Each message names the URL and the type it received, which tells you exactly which file to relabel.

If you use a CDN, purge its cache after the change and check again: cached responses may keep the old headers until they expire.

8. Edge cases worth checking

  • Sent twice. When the origin and the CDN both add the header, many HTTP clients combine the two into one value, nosniff, nosniff. Browsers read the first value and still apply the protection, but strict tools, including Sitelemetry, compare against the exact value and report it. Remove one of the two.
  • Different spelling. NoSniff works in browsers but does not match an exact check. Values such as nosniff; mode=block are copied from the old X-XSS-Protection syntax and are not valid; send plain nosniff.
  • Only some responses. The home page has the header but static files served by another layer, redirects or 404 pages do not. The header matters most on those other responses.
  • Subdomains and other hosts. A CDN host such as static.example.com or a separate upload domain has its own configuration and needs the header set there.
  • HTML without a type. nosniff does not fix a missing Content-Type on your pages; a page without one may be shown as plain text or handled differently by browsers. Always send the type explicitly.

For the wider set of response headers that belong next to this one, see the TLS and security headers guide, and the website audit glossary explains the terms used in scan results.

9. What Sitelemetry checks

The finding http.header.content-type-options.missing comes from the HTTP security headers module. It requests the home page (root URL) of the scanned origin, follows redirects and compares the value of X-Content-Type-Options on the final response with exactly nosniff. Anything else, including a missing header, is reported with severity low, the observed value as evidence and the remediation to add X-Content-Type-Options: nosniff.

What the response containsEvidence shownResult
No headerx-content-type-options=missingFinding, low
nosniffNoneNo finding
NoSniffx-content-type-options=NoSniffFinding: the comparison is exact; send the lowercase value
Header sent twiceThe combined value, for example nosniff, nosniffFinding: send the header once
Any other valueThe observed valueFinding, low

The check is passive and runs in every scan profile on every plan: Free ($0), Starter ($49/month), Professional ($149/month) and Enterprise ($249/month). It reads only what any visitor receives, so it needs no ownership verification on its own: the free Launch Readiness Snapshot, which you can also open through the security headers checker, runs it without signup, and a Free-plan security audit runs it even before you verify the site. A security audit that also includes checks that need ownership proof, as paid-plan audits do by default, asks you to verify the site first. If the response is a bot challenge, an access denial or an edge error page, the module reports the result as not measured instead of raising header findings. The same module also reports on Content-Security-Policy, HSTS, clickjacking protection, Referrer-Policy, cookie flags and server version disclosure; the security headers check guide covers them together.

Its limits: it reads only the home page response, so it does not check the Content-Type of your scripts, stylesheets, API responses or uploads, and it does not test whether a browser would block anything. Use the curl commands above for those. Sitelemetry is an automated audit tool, not a penetration test or a compliance attestation. For the broader picture, see the website security audit guide or compare plans on the pricing page.

Common questions

Do modern browsers still need X-Content-Type-Options: nosniff?

Yes. Current browsers follow the WHATWG standards, which still allow sniffing when a type is missing or generic. The header is what makes them block scripts and stylesheets with the wrong type and stop sniffing toward HTML. OWASP continues to recommend it on all responses.

Should the header be on every response or only on HTML pages?

On every response. Its strongest effects apply to resources loaded as scripts or stylesheets, to data such as JSON, and to user uploads. Setting it at the web server or CDN for all paths, with the nginx always parameter or Apache Header always set, covers error pages and static files too.

Why does Sitelemetry still report the finding after I added the header?

The check compares the value with exactly nosniff. Common causes are a different spelling such as NoSniff, the header being sent by both the CDN and the origin so the values arrive combined as nosniff, nosniff, or a cached response from before the change. Send the header once in lowercase and purge the CDN cache.

Can adding nosniff break my site?

Only if resources are mislabelled. Scripts served as text/plain or application/octet-stream and stylesheets served as anything other than text/css will be blocked. Check asset types with curl first, fix them, test on staging with the browser console open, then enable the header in production.

Does nosniff replace Content-Security-Policy or upload validation?

No. It stops the browser from reinterpreting responses, but it does not control where scripts may load from and does not make unsafe uploads safe. Keep a Content-Security-Policy, validate and relabel uploaded files, and serve user content from a separate domain where possible.

Sources & further reading

  1. MDN: X-Content-Type-Options headerdeveloper.mozilla.org
  2. MDN: Content-Type headerdeveloper.mozilla.org
  3. WHATWG MIME Sniffing Standardmimesniff.spec.whatwg.org
  4. WHATWG Fetch Standardfetch.spec.whatwg.org
  5. RFC 9239: Updates to ECMAScript Media Typeswww.rfc-editor.org
  6. OWASP HTTP Headers Cheat Sheetcheatsheetseries.owasp.org
  7. OWASP File Upload Cheat Sheetcheatsheetseries.owasp.org
  8. nginx: ngx_http_headers_module (add_header)nginx.org
Sitelemetry team

Prepared by the Sitelemetry editorial team. Explore the linked sources for further detail.

SITELEMETRY

Put what you learned to work.

Explore your website’s structure, settings and signals with Sitelemetry.