To check vulnerability in our app servers, we ran Qualys scan. From the report we found our app servers are vulnerable to slow HTTP Post attack. To mitigate this attack, we have configured nginx in front of app servers based on the Qualys report (https://blog.qualys.com/securitylabs/2011/11/02/how-to-protect-against-slow-http-attacks). According to Qualys, if a servers keep the connection open for more than 120 seconds, they consider that server is vulnerable to slow HTTP Post attack. Eventhough nginx default timeout is 60s, it keeps the connection for more than 2 minutes in our app server. We also checked the nginx conneciton status, it keeps the connection in writing state for more than 2 minutes.
Please help us to configure nginx to prevent from slow HTTP Post attack.
Current nginx Configuration
user nginx;
worker_processes auto;
worker_rlimit_nofile 102400;
events {
worker_connections 100000;
}
access_log off;
autoindex off;
limit_req_zone $binary_remote_addr zone=req_limit_per_ip:10m rate=2r/s;
limit_conn_zone $binary_remote_addr zone=limitzone:10m;
limit_conn_status 403;
limit_req_status 403;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 20 15;
client_body_timeout 5s;
client_header_timeout 5s;
send_timeout 2;
reset_timedout_connection on;
types_hash_max_size 2048;
server_tokens off;
client_body_buffer_size 100K;
client_header_buffer_size 1k;
client_max_body_size 100k;
large_client_header_buffers 2 1k;
include /etc/nginx/mime.types;
default_type application/octet-stream;
upstream backend {
server 127.0.0.1:8080 max_conns=150;
}
server {
listen 443 ssl http2 default_server;
\# listen [::]:443 ssl http2 default_server;
server_name *******;
underscores_in_headers on;
if ($request_method !~ ^(GET|HEAD|POST|PUT|DELETE)$ ) {
return 444;
}
*** ssl configuration ***
.....
location / {
limit_conn limitzone 20;
limit_req zone=req_limit_per_ip burst=5 nodelay;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_cookie_path / "/; HTTPOnly; Secure; SameSite=strict";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto https;
proxy_pass http://backend;
}
}