【问题标题】:redirects using htmlspecialchars/htmlentities使用 htmlspecialchars/htmlentities 重定向
【发布时间】:2016-05-26 01:59:44
【问题描述】:
我现在有这种重定向
Redirect::to(htmlspecialchars('home.php'));
但是当我在 home.php 上输入这个时:/%22%3E%3Cscript%3Ealert('hacked')%3C/script%3E
结果如下:
但是为什么?他们说它会被转换,所以漏洞利用尝试会失败,但为什么在我的不是呢?
【问题讨论】:
标签:
php
xss
html-entities
htmlspecialchars
【解决方案1】:
htmlspecialchars 将特殊字符编码为它们在通过参数传递的字符串中的 HTML 等价物。
你的代码
Redirect::to(htmlspecialchars('home.php'));
只对字符串home.php进行编码,并将其传递给Redirect::To-Function,并且不对整个页面的输出使用htmlspecialchars。
要解决这个问题,您必须在 home.php 的每个输出上使用它,如下所示:
<?php
$new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);
echo $new; // <a href='test'>Test</a>
?>
(示例来自:http://php.net/htmlspecialchars)