5.1.2 Ensure only approved HTTP methods are allowed

Information

Following the principle of least functionality, an NGINX server should be configured to reject any HTTP methods that are not explicitly required by the application. While standard web browsing typically only needs GET, POST, and HEAD, modern RESTful APIs might require methods like PUT, PATCH, or DELETE . Any method not essential for the application's functionality should be blocked at the web server level.

Disabling unused HTTP methods mitigates the risk of unintended server interaction and can prevent certain classes of web application attacks. For example, if an attacker finds a way to bypass application-layer authentication, an enabled but unused PUT or DELETE method on the web server could potentially lead to unauthorized file modification or deletion. By explicitly denying such methods, NGINX ensures that requests never even reach the backend application and therefore significantly reducing the attack surface.

NOTE: Nessus has provided the target output to assist in reviewing the benchmark to ensure target compliance.

Solution

There are two recommended methods to restrict HTTP verbs.

Method 1 (Preferred): Using limit_except This directive is designed for this purpose and is considered the cleanest approach. It restricts all methods except for the ones listed.

location /api_login/ {

# Only allow GET, HEAD, and POST methods for this location.
limit_except GET HEAD POST {
deny all;
}

# ... other directives ...
}

Method 2 (Alternative): Using an if conditionThis method offers more flexibility, such as returning a non-standard status code like 444, which simply closes the connection without sending a response header.

location / {

# If the request method is NOT one of GET, HEAD, or POST
if ($request_method !~ ^(GET|HEAD|POST)$) {
# --> close the connection immediately.
return 444;
}

# ... other directives ...
}

Impact:

An overly restrictive filter can block legitimate application functionality. Before implementing these restrictions, it is crucial to coordinate with application developers to get a definitive list of all required HTTP methods for every application endpoint. Incorrectly blocking a required method (e.g., PUT for a file upload feature) will cause parts of the application to fail.

See Also

https://workbench.cisecurity.org/benchmarks/18528

Item Details

Category: PLANNING, SYSTEM AND SERVICES ACQUISITION

References: 800-53|PL-8, 800-53|SA-8, CSCv7|9.2

Plugin: Unix

Control ID: 46f10e04b280f00edee940bb0b5cf0ee9a99365dc6ec7dc527fb0d6898bd16f2