使用htmlspecialchars / htmlentities重定向

时间:2016-05-26 01:59:45

标签: php xss html-entities htmlspecialchars

我现在有这种重定向

Redirect::to(htmlspecialchars('home.php'));

但是当我在home.php上输入此内容时:/%22%3E%3Cscript%3Ealert('hacked')%3C/script%3E

结果如下: enter image description here

但为什么呢?他们说它会转换,所以漏洞利用尝试将失败,但为什么我的不是?

1 个答案:

答案 0 :(得分:0)

htmlspecialchars将特殊字符编码为由参数传递的字符串中的HTML等效字符。 你的代码

Redirect::to(htmlspecialchars('home.php')); 

仅对字符串home.php进行编码并将其传递给Redirect::To - 函数,并且不在整页输出中使用htmlspecialchars。

要解决此问题,您必须在home.php中的每个输出上使用它,如下所示:

<?php
$new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);
echo $new; // &lt;a href=&#039;test&#039;&gt;Test&lt;/a&gt;
?>

(例如:http://php.net/htmlspecialchars

相关问题