我决定亲自测试一下。这个
$_SERVER['SCRIPT_NAME']
变量提供到所请求文件的路径,即使它是索引文件,也没有get参数或其他任何内容。php文档声明它包含
路径
但它似乎是相对于文档根目录的,就像
PHP_SELF
,但不存在安全漏洞。
请求时的输出
example.com/?foo=bar
:
__FILE__: /var/www/index.php
PHP_SELF: /index.php
SCRIPT_NAME: /index.php
REQUEST_URI: /?foo=bar
parse_url(REQUEST_URI): /
__FILE__: /var/www/pathtest.php
PHP_SELF: /index.php
SCRIPT_NAME: /index.php
REQUEST_URI: /?foo=bar
parse_url(REQUEST_URI): /
以及请求时的输出
example.com/index.php/XSS
:
__FILE__: /var/www/index.php
PHP_SELF: /index.php/XSS # note the XSS exploit (this is bold in browser)
SCRIPT_NAME: /index.php # No exploit here
REQUEST_URI: /index.php/%3Cstrong%3EXSS%3C/strong%3E
parse_url(REQUEST_URI): /index.php/%3Cstrong%3EXSS%3C/strong%3E
__FILE__: /var/www/pathtest.php
PHP_SELF: /index.php/XSS
SCRIPT_NAME: /index.php
REQUEST_URI: /index.php/%3Cstrong%3EXSS%3C/strong%3E
parse_url(REQUEST_URI): /index.php/%3Cstrong%3EXSS%3C/strong%3E
正如你所看到的,
$服务器['脚本名称']
始终返回最初处理请求的文件,即URL中的文件,而不存在任何XSS风险。