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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥188 寻找能做王者评分提取的
    • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
    • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
    • ¥15 写论文,需要数据支撑
    • ¥15 identifier of an instance of 类 was altered from xx to xx错误
    • ¥100 反编译微信小游戏求指导
    • ¥15 docker模式webrtc-streamer 无法播放公网rtsp
    • ¥15 学不会递归,理解不了汉诺塔参数变化
    • ¥15 基于图神经网络的COVID-19药物筛选研究
    • ¥30 软件自定义无线电该怎样使用