问题描述
|
假设我是给一些通过nginx托管帐户的人。如果我要在他们的虚拟主机配置文件中添加一行,其中包括驻留在其主目录中的一个额外的配置文件,这是否会导致某种形式的安全漏洞?
这是用户的虚拟主机文件:
server {
listen 80;
server_name user.example.com;
access_log /var/log/nginx/user.access.log;
location / {
root /home/user/htdocs;
index index.html index.htm index.php;
}
location ~ \\.php$ {
fastcgi_pass unix:/var/run/php-fastcgi/php-fastcgi.socket;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/user/htdocs$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
# The important bit
include /home/user/extra_config;
}
从理论上讲,这将与cron作业结合在一起,该作业将检查每个extra_config的时间戳,并在必要时重新加载nginx。理想情况下,用户将利用此功能拒绝对私有文件/目录的访问或创建重写-基本上,它将替代.htaccess。但是这种方法有什么陷阱吗?是否有更好的方法来实现?
解决方法
最好只允许列入白名单的配置指令。您不希望恶意用户(\“ Eve \”)劫持其他用户的流量。例如,我相信用户可以构建如下配置:
}
server {
listen 80;
server_name alice.example.com;
root /home/eve/htdocs;
}
server {
listen 80;
server_name bob.example.com;
root /home/eve/htdocs;
}
server {
listen 80;
server_name passwd.example.com;
root /etc/passwd;
相反,在理想情况下,您将通过某种专门构建的UI进行输入,然后根据该用户输入自己构建适当的nginx配置。例如,我允许用户以类似的方式指定IP禁止-我的UI仅接受IP列表。然后,我通过正则表达式验证IP的格式,并写出nginx deny指令。