When you set the X-Content-Type-Options header with the value nosniff, you instruct the browser not to "guess" or "sniff" the file type but to strictly adhere to the type declared by the server. This reduces the risk of certain content being interpreted as executable when it should not be.
.htaccess file if you use one).Header set X-Content-Type-Options "nosniff"/etc/nginx/sites-available/your-site).server block: add_header X-Content-Type-Options "nosniff";sudo systemctl restart nginxheader("X-Content-Type-Options: nosniff"); Use a middleware like helmet to set the header automatically:
const helmet = require('helmet');
app.use(helmet.noSniff()); Or set it manually:
app.use((req, res, next) => {
res.setHeader('X-Content-Type-Options', 'nosniff');
next();
}); from flask import Flask, Response
app = Flask(__name__)
@app.after_request
def set_headers(response):
response.headers['X-Content-Type-Options'] = 'nosniff'
return response After setting the header, test your website to ensure itโs working:
X-Content-Type-Options header with the value nosniff.Setting this header is a simple but effective way to enhance your website's security. It ensures that browsers handle files correctly and reduces the risk of attacks caused by file type mismatches.