X-Content-Type-Options: nosniff is one of the most frequently reported web findings, yet few teams can say exactly what it changes in the browser or why a scanner cares about it on an image or a JSON API. The header is a single word, but its effect depends on the request destination, the Content-Type the server sends and how proxies and CDNs merge headers. This guide explains the behaviour defined in the WHATWG Fetch and MIME Sniffing standards, why tools such as OWASP ZAP raise it, how to set it on common servers and edges without breaking content, and how it relates to Opaque Response Blocking. It is written for web developers, AppSec engineers and platform teams who own reverse proxies and CDN configuration. For the wider header baseline, see the Security Headers Guide.
Key takeaways
- It enforces types for two destinations. Under the Fetch Standard, nosniff blocks script-like requests whose response is not a JavaScript MIME type, and style requests whose response is not text/css.
- It stops guessing everywhere else. For navigations and other responses the browser uses the supplied Content-Type instead of sniffing, so a text/plain upload is not rendered as HTML.
- The header is only half the fix. nosniff makes the declared Content-Type authoritative, so a wrong or missing Content-Type becomes a breakage, not a guess. Fix types first.
- Set it on every response, including errors. nginx and Apache skip error and redirect responses unless you use the always options, which is a common cause of repeat scanner findings.
- It feeds cross-origin protections. OWASP ASVS 5.0 V3.4.4 notes it enables Cross-Origin Read Blocking, and the Opaque Response Blocking proposal uses nosniff to block HTML, JSON, XML and text/plain responses fetched cross-origin without CORS.
What MIME sniffing is
Every HTTP response is meant to declare what it contains through the Content-Type header, for example text/html; charset=utf-8 or application/json. Historically browsers did not fully trust that declaration. Servers often sent no Content-Type, a generic one such as application/octet-stream, or the wrong one, so browsers inspected the first bytes of the body and computed their own type. The WHATWG MIME Sniffing Standard defines this process: it distinguishes the supplied MIME type (what the server said) from the computed MIME type (what the browser decides to treat it as).
Sniffing helps broken sites render, but it creates MIME confusion. The OWASP HTTP Headers Cheat Sheet describes the risk as sniffing that can "transform non-executable MIME types into executable MIME types". Typical cases:
- User uploads: a file accepted as a harmless type contains HTML or script markup, and a browser that sniffs renders it as an HTML document on your origin, which is stored cross-site scripting. See the File Upload Security Guide.
- Script inclusion of non-script data: a page on another site loads a JSON, CSV or text endpoint of yours through a script tag. If the browser executes it, data can leak or code can run in an unexpected context. See the CAPEC-111 JSON Hijacking (aka JavaScript Hijacking).
- Stylesheet inclusion of non-CSS data: lenient CSS parsing of HTML or other content loaded as a stylesheet can expose fragments of that content to the including page.
The MIME Sniffing Standard defines a no-sniff flag. When it is set and the server supplied a usable type, the computed type is simply the supplied type. When the supplied type is missing or a placeholder (unknown/unknown, application/unknown or */*), the browser still runs the unknown-type rules, but with scriptable sniffing turned off, so it will not decide that the content is HTML.
What nosniff changes in the browser
The header has one valid value. The Fetch Standard gives the ABNF as X-Content-Type-Options = "nosniff", case-insensitive, and its "determine nosniff" algorithm only checks the first value in the header list. If a proxy prepends a different value to a combined header, the browser treats the response as if nosniff were absent.
Blocking for script-like and style destinations
Fetch defines a check called "should response to request be blocked due to nosniff". If nosniff is present, the browser extracts the MIME type from Content-Type and compares it with the request destination. A blocked response becomes a network error: the script does not run or the stylesheet does not apply, and the console reports a MIME type error.
| Request destination | Examples | Allowed with nosniff | Blocked with nosniff |
|---|---|---|---|
| Script-like: script, worker, sharedworker, serviceworker, audioworklet, paintworklet | <script src>, new Worker(), navigator.serviceWorker.register() | A JavaScript MIME type, for example text/javascript | Missing or unparseable Content-Type, text/plain, application/json, text/html, application/octet-stream |
| style | <link rel="stylesheet">, @import | text/css (parameters such as charset allowed) | Missing Content-Type, text/plain, text/html, application/octet-stream |
| Navigation (document) | Opening the URL directly, an iframe | Rendered according to the supplied Content-Type | Not blocked, but a non-HTML type is not sniffed into HTML |
| image, media, font and others | <img>, <video>, fetch() | Not subject to the nosniff block | None from this check (the spec notes image was not compatible with deployed content) |
The JavaScript MIME types are listed in the MIME Sniffing Standard and include text/javascript, application/javascript, application/ecmascript and several legacy text/ forms such as text/x-javascript. Serve text/javascript for new work. Note that Fetch separately blocks script-like requests whose type starts with audio/, image/ or video/ or is text/csv, whether or not nosniff is set. nosniff widens that rule to every non-JavaScript type, including a missing Content-Type.
The Fetch Standard also warns that XSLT can cause script execution but is not part of the script-like set. Serve XSL with an XML type and do not rely on nosniff to control it.
No sniffing on navigations
MDN states that the header prevents a browser from treating a response as text/html when it is loaded in a browsing context and the Content-Type is absent or indicates a non-HTML type. A file served as text/plain with nosniff displays as text even if it contains markup. This is the property that protects user content, logs and raw API output opened directly in a tab.
Why scanners flag a missing header
Almost every DAST tool, header grader and external attack surface scanner checks for nosniff, because it is cheap, standard and listed in OWASP ASVS 5.0 as V3.4.4 (Level 2): all HTTP responses should carry X-Content-Type-Options: nosniff. The OWASP ZAP passive rule is a useful reference because its source is public.
| Property | OWASP ZAP passive rule 10021 | What it means for triage |
|---|---|---|
| Alert name | X-Content-Type-Options Header Missing | Raised when the header is absent or no value contains nosniff |
| Risk and confidence | Low risk, medium confidence | A hardening gap, not an exploitable bug on its own |
| Weakness mapping | CWE-693 Protection Mechanism Failure, WASC-15 Application Misconfiguration | Map to configuration baselines, not to a vulnerability class |
| Responses checked | Only responses with a non-empty body | 204 and empty responses do not alert |
| Errors and redirects | Skipped at the default and high thresholds, included at the low threshold | Low-threshold scans will surface 3xx, 4xx and 5xx responses that your server config misses |
Findings that look like false positives
- Images, fonts and media: nosniff does not block these destinations, so the direct risk is small. The finding is still worth fixing because the same files may be opened as navigations, and a site-wide header is simpler than per-type exceptions.
- JSON and other API responses: an API that is never rendered still benefits. A browser loading it cross-origin through a script tag will refuse it, and ORB uses nosniff to block JSON responses read without CORS. Fix it at the gateway rather than suppressing it.
- Third-party hosts: findings on a SaaS or CDN host you do not control should be routed to the owner or accepted with a recorded rationale, not suppressed globally.
- Redirects and error pages: these are the most common real misses. Error pages often reflect input, which is why ZAP's own guidance notes the issue "still applies to error type pages".
Treat the finding as a configuration defect: fix it at the layer that serves every response, then confirm with a low-threshold rescan. See SAST vs DAST for where passive checks fit in a testing programme.
Setting it correctly on servers and CDNs
Set the header once, at the layer that sees every response, and make sure it survives errors, redirects and upstream merging. The snippets below are configuration only.
| Layer | Configuration | Gotcha from the official documentation |
|---|---|---|
| nginx | add_header X-Content-Type-Options "nosniff" always; | Without always, add_header applies only to 200, 201, 204, 206, 301, 302, 303, 304, 307 and 308. Directives are inherited only if the current level has no add_header of its own (add_header_inherit, from 1.29.3, can change this). |
| Apache httpd (mod_headers) | Header always set X-Content-Type-Options "nosniff" | The default onsuccess table is not used for locally generated non-2xx responses, and headers from CGI or mod_proxy_fcgi live in the always table, so mixing tables can duplicate the header. |
| IIS | <add name="X-Content-Type-Options" value="nosniff" /> under system.webServer/httpProtocol/customHeaders | A <clear /> at a lower level removes inherited custom headers, including this one. |
| Amazon CloudFront | Response headers policy, security headers, X-Content-Type-Options set to true | With origin override true, the policy header replaces the origin's; with false, the origin's header is kept. Either way the header is added if the origin omits it. |
| Node.js with Helmet | app.use(helmet()) | Helmet sets X-Content-Type-Options: nosniff by default; it can be disabled explicitly, so check for overrides. |
Choosing the layer
- Edge or reverse proxy: the best default for organisations with many applications. One rule covers legacy apps, error pages generated by the proxy and static buckets.
- Application framework: useful as a second layer and for teams that deploy without a shared proxy. Watch for duplicates when both layers add the header.
- Small teams: set it in the hosting platform or CDN baseline and verify with MDN HTTP Observatory or a ZAP baseline scan.
- Large organisations: publish a header standard, enforce it in ingress templates and infrastructure as code, and assert it in CI. Duplicate headers are harmless only if every value is nosniff; a first value that is anything else disables it.
Pairing nosniff with correct Content-Type
The OWASP cheat sheet's recommendation has two parts: set Content-Type correctly throughout the site, then send nosniff. Doing the second without the first is how teams break production. Once nosniff is on, a script served as text/plain or a stylesheet served as application/octet-stream simply stops loading.
| Content | Content-Type to send | Common mistake |
|---|---|---|
| JavaScript, including modules and workers | text/javascript; charset=utf-8 | .mjs or bundler output with no mapping, served as application/octet-stream or text/plain |
| CSS | text/css; charset=utf-8 | Stylesheets from object storage uploaded without metadata |
| HTML | text/html; charset=utf-8 | Framework error pages served with a generic type |
| JSON APIs | application/json | text/html on API errors, which a browser may render if opened directly |
| User uploads offered for download | The validated type, or application/octet-stream, plus Content-Disposition: attachment | Echoing the client-supplied type |
| Plain text, logs, raw output | text/plain; charset=utf-8 | No Content-Type at all |
- Object storage and CDNs: buckets store a Content-Type per object, set at upload. Fix the upload pipeline and backfill existing objects before enabling nosniff on that origin.
- Default types: check the server's default for unknown extensions and make sure new build artefacts (source maps, .mjs, .wasm) have explicit mappings.
- Uploads need more than nosniff: OWASP ASVS 5.0 V3.2.1 suggests attachment disposition, the CSP sandbox directive or Sec-Fetch-* checks to stop content rendering in the wrong context. Serve user content from a separate origin where possible. See the Secure File Upload Handling Guide.
- Caches: a cache that stores a response with the wrong type spreads the breakage. See the Web Cache Poisoning and Cache Deception Guide.
Relation to CORB and ORB
Cross-Origin Read Blocking (CORB) and its successor proposal, Opaque Response Blocking (ORB, described by its authors as "CORB++"), stop a page from pulling sensitive cross-origin responses such as HTML or JSON into its own process through no-cors requests like script or image tags. In the ORB algorithm, if nosniff is set and the type is HTML, JSON, XML or text/plain, the response is blocked; later steps also refuse to sniff when nosniff is present. As checked on 26 November 2026, the ORB repository says its text is being upstreamed to the Fetch Standard through pull request 1442 and has not yet been merged, so treat browser behaviour as implementation-specific. ORB's authors recommend Cross-Origin-Resource-Policy for responses that contain secrets, which complements nosniff. See the Same-Origin Policy and Browser Security Model Guide.
Rolling out and measuring
- Inventory: crawl each hostname and record Content-Type and X-Content-Type-Options for HTML, scripts, styles, API, error and redirect responses.
- Fix types first: correct missing or generic Content-Type values for scripts and styles, which are the only resources the header will block.
- Pilot: enable the header on a staging copy or a canary slice of traffic and watch the browser console and real user monitoring for MIME type errors on scripts and styles.
- Enforce at the edge: add the header with the always option or edge policy, then remove app-level duplicates if they cause conflicts.
- Rollback: keep the header in version-controlled config behind a flag. Removing it takes effect on the next response, unlike HSTS.
- Prevent regressions: assert the header and the expected Content-Type in CI and in synthetic monitoring.
Metrics:
- Percentage of sampled responses, including 3xx, 4xx and 5xx, carrying nosniff as the first value.
- Number of script and style responses with a missing or non-matching Content-Type.
- Count of open ZAP 10021 or equivalent findings per application, and time to close.
- Browser console MIME type errors reported by real user monitoring after each release.
Common failure patterns
- Header only on 200 responses: nginx add_header without always or Apache Header set without always leaves error pages and redirects uncovered, so low-threshold scans keep reporting it.
- Location blocks silently dropping it: an nginx location that adds any other header stops inheriting server-level add_header directives, including nosniff.
- Enabling nosniff before fixing types: scripts from a bucket served as application/octet-stream stop running and the header is rolled back for good.
- Treating nosniff as upload security: it does nothing if the server echoes a client-supplied text/html type. Validate type, use attachment disposition and a separate origin.
- Conflicting duplicates: an upstream sends one value and the proxy appends another; only the first value counts.
- Suppressing the finding on APIs: teams mark API alerts as false positives and lose the cross-origin read protection ORB and CORB build on.
Framework mapping
| Framework | Reference | How nosniff relates |
|---|---|---|
| OWASP ASVS 5.0 | V3.4.4 (Level 2) | All responses carry X-Content-Type-Options: nosniff |
| OWASP ASVS 5.0 | V3.2.1 (Level 1) | Prevent rendering in an incorrect context; nosniff plus attachment disposition, CSP sandbox or Sec-Fetch-* checks |
| NIST SP 800-53 Rev 5 | CM-2 Baseline Configuration, CM-6 Configuration Settings | The header belongs in the web server and edge configuration baseline |
| NIST CSF 2.0 | PR.PS-01, PR.PS-06 | Configuration management and secure development practices |
| ISO/IEC 27001:2022 Annex A | A.8.9 Configuration management, A.8.28 Secure coding | Standard header set and correct content typing in code |
| CWE | CWE-693 Protection Mechanism Failure | The weakness ZAP assigns to a missing header |
Practitioner checklist
- Send X-Content-Type-Options: nosniff on every response, including redirects and errors, as the only value.
- Use add_header ... always in nginx and Header always set in Apache, and check location-level inheritance.
- Serve JavaScript as text/javascript and CSS as text/css before enabling the header on an origin.
- Fix Content-Type metadata in object storage upload pipelines and backfill existing objects.
- Serve user uploads from a separate origin with validated types and Content-Disposition: attachment.
- Add Cross-Origin-Resource-Policy to authenticated API responses alongside nosniff.
- Run a low-threshold passive scan to catch error and redirect responses.
- Assert header presence and Content-Type in CI and synthetic monitoring.
Standards and references
- WHATWG: Fetch Standard, X-Content-Type-Options header
- WHATWG: MIME Sniffing Standard
- OWASP: Application Security Verification Standard 5.0
- OWASP: HTTP Headers Cheat Sheet
- MDN: X-Content-Type-Options
- GitHub: Opaque Response Blocking (ORB) explainer
- nginx: ngx_http_headers_module
- Apache HTTP Server: mod_headers
Related NHI Mgmt Group resources: Security Headers Guide · Content Security Policy Guide · Cross-Site Scripting (XSS) Prevention Guide · Deprecated Security Headers Reference