This package provides a small, focused Express/Connect middleware designed to set the `X-Content-Type-Options` HTTP header to `nosniff`. This header is a crucial client-side security measure that prevents browsers from "sniffing" or inferring the MIME type of a response, thereby enforcing the `Content-Type` header explicitly sent by the server. Without it, browsers might execute files (like HTML or JavaScript) that are incorrectly served with a generic MIME type (e.g., `text/plain`), leading to cross-site scripting (XSS) or other content-based attacks. The current stable version is 1.1.0, which was last published in 2019, indicating a highly mature and stable, but infrequently updated, codebase. It is a standalone component of the broader Helmet.js suite, which includes this functionality by default. Its key differentiator is offering granular control over this specific security header without deploying the entire Helmet.js bundle.
npm install dont-sniff-mimetypeVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to apply the `dont-sniff-mimetype` middleware to an Express application, showing how it sets the `X-Content-Type-Options: nosniff` header and prevents a browser from executing an incorrectly typed script.
Remove `dont-sniff-mimetype` if `helmet` is already in use and configured to set this header.
Consider using the full `helmet` package for a more actively maintained and comprehensive security solution, or ensure you understand the implications of using an unmaintained package if adopting this one directly.
Ensure critical assets are always served with the correct `Content-Type` header from the server, as `nosniff` acts as a second line of defense, not a primary fix for incorrect server configurations. Regular testing across target browsers is recommended.
Call the imported function when using it as middleware: `app.use(dontSniffMimetype());`
Verify that your server is sending the correct `Content-Type` header for all resources. For example, JavaScript files should be `application/javascript`, not `text/plain`. If the resource truly isn't meant to be executable, no fix is needed; the package is preventing a potential vulnerability.
Ensure `app.use(dontSniffMimetype());` is called early in your middleware chain, before any routes that might send responses without this header. Inspect network requests in developer tools to confirm the header is present.
No dependency data recorded yet.