Cybersecurity glossary

What is MIME Sniffing?

Learn what MIME sniffing is, how browsers guess content types from response bytes, why it enables XSS via mislabeled files, and how X-Content-Type-Options nosniff stops it.

Web platform securityUpdated July 22, 2026
Also known asContent sniffingMIME type sniffingBrowser content sniffing

Definition

MIME sniffing is a browser behavior in which the user agent inspects response body bytes to infer or override the declared Content-Type when it believes the server mislabeled the resource—sometimes executing non-script types as HTML or JavaScript.

Why MIME sniffing matters

The web trusts servers to label every byte they send. Reality is messier: misconfigured apps, legacy CDNs, and user uploads often ship HTML or script with a text/plain or image/jpeg label. For years, browsers tried to compensate by sniffing content—peeking at magic bytes and markup patterns to guess the “real” type.

That helpfulness became an attack surface. Upload a polyglot file the server calls harmless; a sniffing browser may treat it as executable script in your origin.

How MIME sniffing works

1

Server sends a response

Includes a Content-Type header that may be wrong, generic, or missing.

2

Browser evaluates the label

Checks whether the declared type is authoritative or whether sniffing is allowed for this context.

3

Sniffing algorithm runs

Inspects leading bytes for HTML tags, script markers, or image signatures.

4

Type may be overridden

Browser may upgrade text/plain to text/html or treat content as script-compatible.

5

Content is rendered or executed

Mislabeled uploads run as active content in the page origin.

6

nosniff blocks override

X-Content-Type-Options: nosniff stops guessing for script and other protected contexts.

Sniffing vs declared type

Declared Content-Type

The MIME type the server asserts in the Content-Type response header.

Sniffed type

The type the browser infers from body bytes when sniffing is permitted.

nosniff enforcement

With X-Content-Type-Options: nosniff, script and CSS contexts trust the declared type.

Polyglot uploads

Files valid as multiple formats—classic MIME confusion attack payloads.

MIME sniffing vs X-Content-Type-Options

ConceptWhat it isSecurity role
MIME sniffingBrowser-side content inspection behaviorCan override weak or wrong Content-Type labels—helpful historically, exploitable today
X-Content-Type-Options: nosniffHTTP response header sent by the serverDisables MIME sniffing overrides in protected loading contexts
Correct Content-TypeAccurate server labeling of each resourceFoundation; nosniff enforces it but does not substitute for it
Content-Disposition: attachmentHeader suggesting download instead of inline displayReduces inline execution risk for user-controlled files

Prevention checklist

  • Send X-Content-Type-Options: nosniff on HTML, APIs, and especially user-uploaded or downloadable content.
  • Set precise Content-Type values for every response; never rely on sniffing to ‘fix’ mislabeled files.
  • Validate uploads server-side: extension, magic bytes, and disallow active content in user-controlled storage.
  • Serve untrusted files from a separate origin (cookieless) or with Content-Disposition: attachment.
  • Use Content Security Policy to limit script sources even when MIME labels fail.
  • Avoid generic types like application/octet-stream for browser-rendered paths unless paired with attachment disposition.
  • Test upload endpoints with polyglot HTML/script payloads labeled as text/plain or images.
  • Audit CDN and storage layers that rewrite or strip Content-Type and security headers.

Limits and pitfalls

nosniff does not make wrong Content-Type values safe—it prevents the browser from “fixing” them into executable types in protected contexts. Some legacy browsers and embedded WebViews implement sniffing rules differently.

MIME sniffing is also unrelated to Content Negotiation (choosing among server-offered representations) and CORS (cross-origin read policy). It specifically concerns how a browser classifies bytes it already received.

The practical takeaway

MIME sniffing lets browsers override weak Content-Type labels by inspecting body bytes—a behavior attackers abuse through mislabeled uploads. X-Content-Type-Options: nosniff is the standard server-side switch that turns that guessing off for script and related contexts.

Label every response accurately, send nosniff broadly, and never assume text/plain on an upload means the browser will keep it inert.

Related security terms

Frequently asked questions

What is MIME sniffing in simple terms?

MIME sniffing is when a browser looks at the actual bytes of a file instead of trusting the Content-Type header alone. If it decides the file ‘looks like’ HTML or JavaScript, it may render or execute it even when the server labeled it as plain text.

How does MIME sniffing differ from X-Content-Type-Options?

MIME sniffing is the browser behavior. X-Content-Type-Options: nosniff is the server header that disables that behavior for relevant contexts, forcing the browser to respect the declared Content-Type.

Why is MIME sniffing dangerous?

Attackers upload files the server stores as text/plain or image/* but that contain HTML or script. Sniffing browsers execute the content in the site’s origin, enabling stored XSS.

Does nosniff replace correct Content-Type headers?

No. Always serve accurate Content-Type values. nosniff enforces them more strictly; it does not fix wrong labels by itself.

Is MIME sniffing still a problem in modern browsers?

Browsers have tightened sniffing rules, but mislabeled user uploads, legacy endpoints, and downloadable content remain risky without nosniff and correct types.

How do you prevent MIME sniffing attacks?

Set accurate Content-Type headers, send X-Content-Type-Options: nosniff, validate uploads server-side, serve user content from separate origins or with Content-Disposition: attachment, and use CSP.

References

Explore authoritative guidance and frameworks related to mime sniffing.

Explore every security definition

Return to the glossary to search by term, alias, starting letter, or security category.

Browse glossary