Nginx: 常见漏洞修复(Host头攻击|不安全的Http方法|缺少X-XSS-Protection头部)

Nginx: 常见漏洞修复(Host头攻击|不安全的Http方法|缺少X-XSS-Protection头部)

  • Host头攻击
    在server模块配置:
if ($host !~* xxx.xxx.xxx|xxx.ddd.ddd.ddd) {
    
    
            return 403;
}

或者

if ($http_Host !~* xxx.xxx.xxx:port|xxx.ddd.ddd.ddd:port) {
    
    
            return 403;
}

xxx.xxx.xxx:代表域名
xxx.ddd.ddd.ddd:代表IP
根据需求,可以只写一个或多个条件。
$host不对端口进行判断,$http_Host则对端口进行判断,根据需求选用。

  • 不安全的Http方法
    在server模块配置:
if ($request_method !~* GET|POST) {
    
    
    return 403;
}

HTTP1.0定义了三种请求方法: GET、POST、HEAD
HTTP1.1新增了五种请求方法:OPTIONS、PUT、DELETE、TRACE 、CONNECT
除了GET和POST方法,其他方法都可以视为不安全的方法,根据需求,尽量减少允许的方法。

简单自查:

curl -i -X 方法 httpxxxxxxxxxxxxx
  • 缺少X-XSS-Protection头部
 add_header X-Xss-header  “1;mode=block”;

猜你喜欢

转载自blog.csdn.net/rookie23rook/article/details/114264319
今日推荐