X-Content-Type-Options header
The HTTP X-Content-Type-Options response header indicates that the MIME types advertised in the Content-Type headers should be respected and not changed.
The header allows you to avoid MIME type sniffing by specifying that the MIME types are deliberately configured.
Site security testers usually expect this header to be set (and that the Content-Type header is correctly set for all resources).
The nosniff directive has two effects depending on the context:
- Request blocking: For requests with a destination of
"script"or"style", the browser blocks the response if the MIME type doesn't match an expected type (a JavaScript MIME type for scripts, ortext/cssfor stylesheets). See the Fetch specification for details. - MIME type sniffing disabled: For other response types, including navigations to a new HTML document, the browser uses the supplied
Content-Typeas-is instead of examining the content to infer the type. For example, if a server sends a response withContent-Type: text/plainandX-Content-Type-Options: nosniff, the browser will not interpret it as HTML, even if the content contains HTML markup. This prevents XSS-attacks where user-uploaded content is executed as an HTML document, even if the browser has specified that it should be treated as plain text (or some other type). See the MIME Sniffing specification for details.
| Header type | Response header |
|---|---|
| Forbidden response header | No |
Syntax
X-Content-Type-Options: nosniff
Directives
nosniff-
Blocks a request if the request destination is of type
styleand the MIME type is nottext/css, or of typescriptand the MIME type is not a JavaScript MIME type.It also prevents MIME type sniffing for all other response types, causing the browser to use the declared
Content-Typewithout examining the response content. In particular it prevents a browser from treating a response astext/htmlwhen it is loaded in a browsing context and theContent-Typeheader is absent or indicates a non-HTML type.
Specifications
| Specification |
|---|
| Fetch> # x-content-type-options-header> |
Browser compatibility
See also
Content-Type- The original definition of X-Content-Type-Options by Microsoft.
- Use HTTP Observatory to test the security configuration of websites (including this header).
- Mitigating MIME Confusion Attacks in Firefox