medium HTTP Headers

Missing X-Content-Type-Options Header

Without X-Content-Type-Options: nosniff, browsers can MIME-sniff responses and turn harmless-looking uploads into executable scripts.

Severity
medium
Time to Fix
5 minutes
Difficulty
easy
OWASP
A05:2021 — Security Misconfiguration

What is Missing X-Content-Type-Options Header?

When a server responds without a strict Content-Type, or with a generic one like text/plain, browsers historically "sniffed" the actual content by inspecting the first bytes — rendering a file labeled as text as HTML or script if it looked like it. The X-Content-Type-Options: nosniff header switches this behavior off: the browser must honor the declared Content-Type and refuse to execute anything that is not explicitly declared as executable. The classic attack: a user-uploaded file served from your domain as text/plain or application/octet-stream gets sniffed into a script, turning your upload area into an XSS launcher even when you never intended to serve HTML from it. It is a one-line, defense-in-depth header recommended by OWASP secure headers project.

Why It Matters to Your Business

MIME-sniffing is a real amplifier for any site that hosts user content — avatars, attachments, uploads, or exported files. A single sniffing XSS can steal sessions, perform actions as the victim, and deface content. Security reviewers and automated scanners (including ours) flag the missing header instantly, so it also shows up in every audit report you will ever receive. The cost of fixing is one configuration line; the cost of the XSS it prevents is a full incident response.

How to Fix It

Send the header on EVERY response from your domain (including static files and upload directories).

Nginx (http or server context):
  add_header X-Content-Type-Options "nosniff" always;

Apache (.conf or .htaccess):
  Header always set X-Content-Type-Options "nosniff"

Express.js (helmet sets it by default):
  const helmet = require('helmet');
  app.use(helmet());

Laravel middleware:
  return $response->header('X-Content-Type-Options', 'nosniff');

Static-file CDNs: Cloudflare Transform Rules or your origin config can add the header to every asset.

Verify after deploying: curl -sI https://yoursite.com | grep -i x-content-type-options

Frequently Asked Questions

What is MIME sniffing?

It is browser behavior where the actual content of a response is inspected to decide how to render it, overriding the declared Content-Type. A text file that starts with <script> can be executed as script. The nosniff header forbids this — the browser must strictly respect the declared type.

Is this header still relevant in 2026?

Yes. Modern browsers have narrowed sniffing, but the header remains a hard guarantee for legacy browsers, embedded webviews, and any file served with a permissive Content-Type. OWASP and Mozilla still list it as a baseline secure header.

Can adding nosniff break my site?

Only if you are serving executable content with a deliberately wrong Content-Type (e.g. scripts labeled text/plain) — which is itself a bug. Correctly-typed sites see zero impact.

Technical Classification

OWASP CategoryA05:2021 — Security Misconfiguration
CWE IDCWE-79: Cross-site Scripting
Detected Byheaders, security_features scanner(s)
Severity Levelmedium

How 2MNY Security Can Help

Check if your website has this vulnerability

Our headers, security_features scanner checks for this issue automatically.

Scan My Website Free

Related Vulnerabilities