nginx。拒绝 URL 中任意位置的两点

Pik*_*nik 3 nginx

我需要配置 nginx 服务器,如果 URL 在 URL 中的任何位置包含两点(..),他就会显示 403 页。例如,如果 URL 是“site.sit/index.php?log=../conf.php - web-server 应该检测到尝试去上面的目录并引入 403-messege。我尝试在 conf 中配置这个想法-file nginx 那里:

location \.\. {
    deny all;
    }
Run Code Online (Sandbox Code Playgroud)

但这行不通。

告诉我,我如何实施这个计划?

Ric*_*ith 6

location指令仅查看-左侧的规范化URI,?因此它将错过..参数中的任何序列。

如果您需要检查提交给服务器的原始 URI(包括参数),请改用正则表达式$request_uri

例如:

if ($request_uri ~ \.\.) { return 403; }
Run Code Online (Sandbox Code Playgroud)

请参阅有关使用该指令的注意事项if