【问题标题】: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; // &lt;a href=&#039;test&#039;&gt;Test&lt;/a&gt;
    ?>
    

    (示例来自:http://php.net/htmlspecialchars

    【讨论】:

      猜你喜欢
      • 2010-09-07
      • 2011-10-21
      • 2020-09-30
      • 2014-05-31
      • 1970-01-01
      • 2017-09-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多