首页 > 解决方案 > 具有 xss 漏洞的搜索字段

问题描述

我的搜索字段中有一个 XSS 漏洞,当我输入典型警报('xss')时,窗口就会出现。我使用 vega 和 OWASP ZAP 来了解我的错在哪里,我已经检测到,它在带下划线的代码中,但我不知道如何清理,你能帮我吗?这是我的代码:

<?php
require_once("../include/pictures.php");
require_once("../include/comments.php");
require_once("../include/cart.php");
require_once("../include/html_functions.php");
require_once("../include/functions.php");

session_start();

if (!isset($_GET['query']))
{
   http_redirect("/error.php?msg=Error, need to provide a query to search");
}

$pictures = Pictures::get_all_pictures_by_tag($_GET['query']);

?>

<?php our_header("", $_GET['query']); ?>

<div class="column prepend-1 span-24 first last">
<h2>Pictures that are tagged as '<?= $_GET['query']  ?>'</h2>

   <?php thumbnail_pic_list($pictures); ?>

</div>


<?php our_footer(); ?>

我不能下划线,需要清理的代码是:

'<?= $_GET['query']  ?>'

标签: phpxss

解决方案


用这个

htmlspecialchars($_GET['query'])

推荐阅读