Identification of Content Sniffing

Content sniffing, also known as MIME sniffing, is a security vulnerability that occurs when a web browser or other user agent interprets the content type of a resource incorrectly, potentially leading to security risks such as cross-site scripting (XSS) or cross-site request forgery (CSRF). This vulnerability arises when the server does not properly set the MIME type or Content-Type header for the served content, allowing browsers to interpret it based on its content rather than its declared type. As a penetration tester, identifying content sniffing vulnerabilities involves examining how the browser interprets content types and checking for discrepancies between declared types and actual content. Here's how you can identify content sniffing vulnerabilities:


  1. Inspecting HTTP Headers: Examine the HTTP headers of responses from the server to see if the Content-Type header is set correctly for each resource. Look for inconsistencies between the declared content type and the actual content.
  2. Analyzing Response Bodies: Review the content of HTTP responses to see if the server's declared content type matches the actual content. Use tools such as browser developer tools or proxy tools like Burp Suite to inspect responses.
  3. Testing with Various Browsers: Test the application with different web browsers to see if they interpret content types differently. Some browsers may perform content sniffing even when the Content-Type header is set correctly, leading to security vulnerabilities.
  4. Checking for Cross-Site Scripting (XSS): Test for potential XSS vulnerabilities by injecting script tags into different types of content (e.g., images, CSS files) and observing how the browser interprets them.
  5. Analyzing Cache Behavior: Check if browsers cache responses based on content type. If browsers cache responses incorrectly due to content sniffing, it could lead to security risks such as CSRF attacks.
  6. Reviewing Documentation: Review the application's documentation and server configuration to see if the server is configured to prevent content sniffing. Look for settings related to MIME types and Content-Type headers.


  • Example 1: During testing, a penetration tester discovers that the application serves user-uploaded files with incorrect or missing Content-Type headers. As a result, some browsers interpret these files as executable scripts, leading to potential XSS vulnerabilities.
  • Example 2: The tester notices that the application serves JavaScript files with the Content-Type header set to text/plain instead of application/javascript. Some browsers may perform content sniffing and execute the JavaScript as if it were plaintext, leading to security risks.


  1. Set Correct Content-Type Headers: Ensure that the server sets the correct Content-Type headers for all served resources, including user-uploaded files and dynamically generated content.
  2. Use X-Content-Type-Options Header: Set the X-Content-Type-Options header with the value nosniff to instruct browsers not to perform content sniffing and to rely only on the declared Content-Type header.
  3. Content Security Policy (CSP): Implement a strict CSP to restrict the sources from which content can be loaded, reducing the risk of content sniffing and other security vulnerabilities.
  4. Sanitize User-Generated Content: Validate and sanitize user-uploaded files and other user-generated content to prevent malicious uploads and reduce the risk of content sniffing vulnerabilities.
  5. Regular Security Testing: Conduct regular security testing, including vulnerability scanning and manual testing, to identify and address content sniffing vulnerabilities in web applications.

By identifying and mitigating content sniffing vulnerabilities, penetration testers can help organizations prevent security risks such as XSS and CSRF attacks and protect the integrity of their web applications.