echo $_SERVER['PHP_SELF'];这条语句上直接输出了未过滤的值。追根数源,我们看下 PHP 手册的描述
'PHP_SELF' The filename of the currently executing script, relative to the document root. For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar would be /test.php/foo.bar. The __FILE__ constant contains the full path and filename of the current (i.e. included) file. If PHP is running as a command-line processor this variable contains the script name since PHP 4.3.0. Previously it was not available.原因很明确了,原来是 $_SERVER['PHP_SELF'] 虽然“看起来”是服务器提供的环境变量,但这的确和 $_POST 与 $_GET 一样,是可以被用户更改的。 其它类似的变量有很多,比如 $_COOKIE 等(如果用户想“把玩”他们的 cookie,那我们也是没有办法)。解决方案很简单,使用 [url=http://cn2.php.net/strip_tags]strip_tags[/url]、[url=http://cn2.php.net/htmlentities]htmlentities[/url] 等此类函数过滤或者转义。
echo htmlentities($_SERVER['PHP_SELF']);-- Split -- 上述的例子让我们需要时刻保持谨慎 coding 的心态。Chris Shiflett 在他的 Blog [url=http://shiflett.org/blog/2005/feb/my-top-two-php-security-practices]总结的相当直白[/url],防止 XSS 的两个基本的安全思想就是
Filter input Escape output我将上面翻译成 “过滤输入,转义输出”。详细的内容,可以参考他 Blog 的[url=http://shiflett.org/blog/2005/feb/more-on-filtering-input-and-escaping-output]这篇文章[/url],此处略。
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有