首页 > 解决方案 > 在 Paypal html 表单中防止 XSS 攻击

问题描述

我对站点锁上的 XSS 扫描有一些问题。他们说来自 html 输入表单的一些 URL 是易受攻击的。他们说我通过表格发送的每个参数都是易受攻击的。在这种情况下,漏洞来自 Paypal 输入表单。我使用 Paypal 重定向构建我的网站,因此用户将自己的数据输入到表单中,系统会将其发送到 paypal。这是我的表单代码示例:

<div class="col-md-5">
    <input type="text" class="form-control" name="L_PAYMENTREQUEST_FIRSTNAME" id="L_PAYMENTREQUEST_FIRSTNAME" value="<?=$_SESSION['post_value']['shipping_first_name']?>" readonly="readonly">
</div>

<input type="hidden" name="billing_first_name" value="<?=$_POST['billing_first_name']?>">
<input type="hidden" name="billing_last_name" value="<?=$_POST['billing_last_name']?>">
<input type="hidden" name="billing_email" value="<?=$_POST['billing_email']?>">
<input type="hidden" name="billing_phone" value="<?=$_POST['billing_phone']?>">
<input type="hidden" name="billing_address" value="<?=$_POST['billing_address']?>">
<input type="hidden" name="billing_city" value="<?=$_POST['billing_city']?>">
<input type="hidden" name="billing_postcode" value="<?=$_POST['billing_postcode']?>">
<input type="hidden" name="billing_state" value="<?=$_POST['billing_state']?>">

那是我形式的一部分。我想知道的是该表单有什么问题以及如何防止 Sitelock 扫描 XSS 漏洞?请知道的人可以帮助我。

标签: formspaypalxss

解决方案


您可能不会检查/取消您在输入字段中获得的数据

<script>alert('hacked')</script>在 billing_address 字段中输入

在打印 billing_address 的下一页上,您将看到一个弹出窗口,调用 hacked

在处理您的表单的页面上,您应该验证输入字段没有任何 JavaScript 代码。

例如

<?php
// define variables and set to empty values
$name = $email = $gender = $comment = $website = "";

if ($_SERVER["REQUEST_METHOD"] == "POST") {
  $name = test_input($_POST["name"]);
  $email = test_input($_POST["email"]);
  $website = test_input($_POST["website"]);
  $comment = test_input($_POST["comment"]);
  $gender = test_input($_POST["gender"]);
}

function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}
?>

您需要创建一个类似 test_input 的函数并为所有输入字段运行


推荐阅读