TL;DR
Yes, blocking unwanted HTTP methods (HEAD, TRACE, DELETE, TRACK) is a good security practice. It reduces your server’s attack surface by disabling features rarely needed but potentially exploitable.
Why Block These Methods?
- HEAD: Used to retrieve only the headers of a resource. While generally harmless, it can reveal information about your server and application setup.
- TRACE: Allows sending a request along with its original content back to the client. This is often used for debugging but can be exploited in Cross-Site Scripting (XSS) attacks or to discover hidden headers.
- DELETE: Used to delete a resource. If not properly secured, it could allow unauthorized users to remove data.
- TRACK: A non-standard method sometimes used for web analytics; rarely needed and potentially misused.
How to Block HTTP Methods
The method for blocking these depends on your web server software.
1. Apache
- Edit your virtual host configuration file (e.g.,
/etc/apache2/sites-available/your_site.conf). - Add the following lines within the
<Directory>block:Options -HEAD -TRACE DELETE TRACK - Restart Apache:
sudo systemctl restart apache2
2. Nginx
- Edit your server block configuration file (e.g.,
/etc/nginx/sites-available/your_site). - Add the following lines within the
server { ... }block:if ($request_method ~ ^(HEAD|TRACE|DELETE|TRACK)$) { return 405; } - Restart Nginx:
sudo systemctl restart nginx
3. Microsoft IIS
- Open IIS Manager.
- Select your website or application.
- Double-click “Request Filtering”.
- In the “Hidden Methods” section, click “Add Hidden Method…”.
- Enter
HEAD,TRACE,DELETEandTRACKone at a time, then click OK.
4. Node.js (Express)
- Use middleware to handle unwanted methods:
const express = require('express'); const app = express(); app.use((req, res, next) => { if (['HEAD', 'TRACE', 'DELETE', 'TRACK'].includes(req.method)) { return res.status(405).send('Method Not Allowed'); } else { next(); } });
Testing the Block
- Use a tool like
curlto test if the methods are blocked. For example:curl -X HEAD http://yourdomain.com/somepage curl -X TRACE http://yourdomain.com/somepage curl -X DELETE http://yourdomain.com/somepage curl -X TRACK http://yourdomain.com/somepage - You should receive a
405 Method Not Allowederror for each blocked method.
Important Considerations
- Review your application: Ensure blocking these methods doesn’t break any legitimate functionality.
- Web Application Firewall (WAF): Consider using a WAF for more comprehensive cyber security protection, including HTTP method filtering and other attack mitigation techniques.