X-Content-Type-Options: Set to "nosniff" to prevent the browser from guessing a different content type than the server declared. X-Content-Type-Options: nosniff tells browsers to trust the Content-Type the server sends, instead of guessing the type from the content. Without it, a browser might treat an uploaded text file that contains HTML or JavaScript as a web page or script, and run it. That can turn a harmless file upload into a cross-site scripting vulnerability.
Frequently asked questions about X-Content-Type-Options
What should you keep in mind with X-Content-Type-Options?
It is one of the simplest security headers: one fixed value, no configuration and practically no downside. Add it to every response, through your web server or framework middleware. It only works if your server sends correct content types, so make sure uploaded files and API responses have accurate Content-Type headers. Together with a Content-Security-Policy, it closes several common routes for script injection.
What does an example of X-Content-Type-Options look like?
Use when reviewing or setting HTTP response headers for a web app or API - security headers (Content-Security-Policy, Strict-Transport-Security, X-Frame-Options, X-Content-Type-Options, Referrer-Policy, Permissions-Policy), CORS headers, caching headers (Cache-Control, ETag, Last-Modified, Vary) and cookies (Set-Cookie flags). Also use when a security scan reports missing headers.
OWASP Top 10 security audit and secure coding guidelines for Laravel + React/Inertia.js applications. Use when auditing for vulnerabilities ("run OWASP audit", "security review", "check my app security") or writing secure Laravel code involving auth, payments, file uploads, or API design. Triggers on security-related tasks, payment handling, authentication, or any request to audit a Laravel codeba
Configure Static Application Security Testing (SAST) tools for automated vulnerability detection in application code. Use when setting up security scanning, implementing DevSecOps practices, or automating code vulnerability detection.