X Content Type Options
The following is a quick lesson to recap browser-specific content sniffing vulnerabilities and how they can be mitigated using security headers.
We'll cover the following
When browsers fetch remote sources of content such as JavaScript or images, they are instructed using the Content-Type
header on the type of content.
For example, when a PDF content type is fetched by the browser, the server hints the browser by setting the following header: Content-Type: application/pdf
.
These content types are standardized by the IANA organization as MIME types. A full list of common MIME types can be seen here.
Risk
What happens when the browser is given an incorrect MIME type for a content or not given one at all? In such a case, the browser will attempt to guess the content type by reading and interpreting the content data. This action is referred to as MIME Sniffing.
More information on MIME Sniffing can be found in the official MIME Sniffing standard.
The purpose of this header is to instruct the browser to avoid guessing the web server’s content type, which may lead to an incorrect render.
The X-Content-Type-Options HTTP header is used by IE, Chrome, and Opera to mitigate a MIME based attack.
An example of setting this header:
X-Content-Type-Options: nosniff
Helmet’s implementation:
const helmet = require("helmet");
app.use(helmet.noSniff());
Get hands-on with 1400+ tech skills courses.