为什么当url中有分号时nginx不拒绝请求?

问题描述 投票:0回答:1

我有一个 nginx.conf 如下:

server {
    listen 443 ssl;
    # some other ssl config

    server_name home.aaa.com;

    # some access_log and error_log config

    location /actuator/ {
        allow 10.1.1.0/24;
        deny all;
        proxy_pass http://10.1.1.1:8989;
    }   

    location / {
        proxy_pass http://10.1.1.1:8989;
    }   
}

当我访问https://home.aaa.com/actuator/prometheus时,nginx拒绝这个请求并返回403,这就是我所期望的。

当我访问https://home.aaa.com/actuator/prometheus;%2f..%2f..//时,nginx在access.log中输出新行:

1.202.147.132 - - [15/Jan/2024:11:00:55 +0800] “GET /actuator/prometheus;%2f..%2f..// HTTP/1.1” 200 7889841 “-” “Mozilla/ 5.0 (Windows NT 10.0; Win64; x64; rv:121.0) Gecko/20100101 Firefox/121.0" "-" https "home.aaa.com" "1.025" "0.270" "10.1.1.1:8989"

并且 nginx error_log 中没有日志。但我希望 nginx 也会拒绝这个请求。

我不知道为什么第二个请求被代理到后端服务器,如何调试这个问题?

谢谢!

security nginx url reverse-proxy directory-traversal
1个回答
0
投票

url解码后的url

https://home.aaa.com/actuator/prometheus;%2f..%2f..//
https://home.aaa.com/actuator/prometheus;/../..//
。在 nginx
$uri
中,这将是
/
。那么它与
location /actuator/
不匹配。

这是插图,

#nginx config
    location /actuator/ {
         return 403 $uri;
    }   

    location / {
        return 200 $uri;
    }

以及卷曲结果

$ curl -sS 'xxxx/actuator/prometheus;%2f..%2f..//'
/

$ curl -sS 'xxxx/actuator/prometheus'
/actuator/prometheus
© www.soinside.com 2019 - 2024. All rights reserved.