duanlu5055 2017-05-03 07:38
浏览 446

Nginx + fastcgi script_filename uri安全

I have a location block which handles the /api directory of my site exclusively.

Is it safe to run fastcgi_param SCRIPT_FILENAME from one directory down and let the URI handle pointing to the api directory? If not, how can this be handled better?

Currently, /var/www/development$uri becomes /var/www/development/api/... and want to ensure this cannot be exploited so that the var/www/development directory isn't be accessed. Setting it to /var/www/development/api$uri would incorrectly point to /var/www/development/api/api/....

The two locations blocks I currently have setup are as follows...

location ^~ / {
    root /var/www/development/app;
    try_files $uri $uri/ =404;

    location ~ \.php$ {
            try_files $uri =404;

            fastcgi_split_path_info ^(.+\.php)(/.+)$;

            fastcgi_pass unix:/run/php/php7.1-fpm.sock;
            fastcgi_index index.php;
            include fastcgi.conf;
    }
}

location /api {
    alias /var/www/development/api;
    try_files $uri $uri/ =404;

    location ~ \.php$ {
            try_files $uri =404;

            fastcgi_split_path_info ^(.+\.php)(/.+)$;

            fastcgi_pass unix:/run/php/php7.1-fpm.sock;
            fastcgi_index index.php;
            include fastcgi.conf;
            fastcgi_param SCRIPT_FILENAME /var/www/development$uri; # IS THIS OK FROM A SECURITY STANDPOINT?
    }

    error_page 403 404 500 /error/api.json;
}

for reference, the directories are...

/var/www/development        < Base directory
/var/www/development/app    < Handles http://example.com/*
/var/www/development/api    < Handles http://example.com/api/*
/var/www/development/assets < PHP Composer, custom classes, etc
/var/www/development/static < Error pages, etc
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100