Content sniffing - Web Security Best Practices (2024)

  1. Home
  2. / Web Best Practices
  3. / Web Security Best Practices
  4. / Content sniffing

A content sniffing attack typically involve tricking a browser into executing a script that is disguised as another file type. These attacks can be protected against with correctly configured response headers.

The X-Content-Type-Options response HTTP header is a marker used by the server to indicate the MIME types advertised in the Content-Type headers should not be changed and be followed … This header was introduced by Microsoft in IE 8 as a way for webmasters to block content sniffing that was happening and could transform non-executable MIME types into executable MIME types.

Content sniffing - Web Security Best Practices (2)

Use content sniffing protection

Turn off browser content sniffing to protect against content sniffing exploits. When processing a response, browsers sometimes ignore the MIME type in the Content-Type header and guess the type based on the contents of the response. This is called content sniffing and is done to improve the user experience when Content-Type headers are inaccurate or missing. However, this behaviour can be exploited. For example, if your site allows users to share images, an attacker might be able to upload a specially crafted image file that contains JavaScript code. A browser performing content sniffing might then be tricked into executing the malicious file. To reduce content sniffing attacks, set the X-Content-Type-Options response header to nosniff. This tells browsers to avoid guessing response types and to rely only on the Content-Type header.

Learn more

  1. Reducing MIME type security risks

    msdn.microsoft.com

  2. OWASP Secure Headers Project

    www.owasp.org

  3. Content sniffing

    en.wikipedia.org

  4. X-Content-Type-Options

    developer.mozilla.org

Set MIME types

All responses should accurately specify their MIME type so that browsers don’t have to rely on content sniffing. When the X-Content-Type-Options: nosniff response header is used to disable content sniffing, browsers rely on the Content-Type header to determine the type of each response. To avoid issues, set the Content-Type header of all responses to an accurate MIME type.

Learn more

  1. X-Content-Type-Options

    developer.mozilla.org

  2. Properly Configuring Server MIME Types

    developer.mozilla.org

  3. Content sniffing

    en.wikipedia.org

  4. Types (Section 7.2.1)

    www.w3.org

  5. Mitigating MIME Confusion Attacks in Firefox

    blog.mozilla.org

More articles in this series

➜ This article is from our comprehensive Web Security Best Practices guide.

➜ Next article in this series: Response headers

➜ Previous article in this series: HSTS

Want to know when we write new articles? 😄 Get news and updates about web best practices from us viaTwitter,Facebook orour newsletter.

Content sniffing - Web Security Best Practices (2024)
Top Articles
Latest Posts
Article information

Author: Zonia Mosciski DO

Last Updated:

Views: 5911

Rating: 4 / 5 (71 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Zonia Mosciski DO

Birthday: 1996-05-16

Address: Suite 228 919 Deana Ford, Lake Meridithberg, NE 60017-4257

Phone: +2613987384138

Job: Chief Retail Officer

Hobby: Tai chi, Dowsing, Poi, Letterboxing, Watching movies, Video gaming, Singing

Introduction: My name is Zonia Mosciski DO, I am a enchanting, joyous, lovely, successful, hilarious, tender, outstanding person who loves writing and wants to share my knowledge and understanding with you.