Javascript 针对服务器端处理Draw请求的交叉脚本攻击

Javascript 针对服务器端处理Draw请求的交叉脚本攻击,javascript,json,datatable,Javascript,Json,Datatable,链接: “此对象作为响应的绘图计数器-来自作为数据请求一部分发送的绘图参数。请注意,出于安全原因,强烈建议您将此参数强制转换为整数,而不是简单地将其在绘图参数中发送的内容回显给客户端,以防止跨站点脚本编写(XSS)”攻击。” 有人能用幼儿园的语言解释一下这意味着什么吗?这是非常令人沮丧的这就像读胡言乱语对我来说。所以只要把draw=1,然后就没有黑客了?生活容易吗 我将发布代码,这样它就不会关闭: $(document).ready(function() { var asc = true; $(

链接:

“此对象作为响应的绘图计数器-来自作为数据请求一部分发送的绘图参数。请注意,出于安全原因,强烈建议您将此参数强制转换为整数,而不是简单地将其在绘图参数中发送的内容回显给客户端,以防止跨站点脚本编写(XSS)”攻击。”

有人能用幼儿园的语言解释一下这意味着什么吗?这是非常令人沮丧的这就像读胡言乱语对我来说。所以只要把draw=1,然后就没有黑客了?生活容易吗

我将发布代码,这样它就不会关闭:

$(document).ready(function() {
var asc = true;
$('#example').DataTable( {
"processing": true,
"serverSide": true,
"ajax": {
"url": "server.php",
"type": "POST",
},


columnDefs: [{
targets: -1,
defaultContent: '<button type="button">Delete</button>'
}],
rowGroup: {
dataSrc: 1
}
});
});
 </script>
   <body>

 <table id="example" class="display" style="width:100%" class="table table-striped table-bordered table-hover table-condensed">
  <thead class="thead-inverse">
 <tr>
 <th> ID </th>
 <th>First Name </th>
 <th>Last Name </th>
 <th>Position </th>
 <th>Date </th>
<th>Updated </th>
 <th>Action</th>
 </thead> 
 </tr>
         <tbody>

         </tbody>
     </table>
     </div>         
 <?php

 $data=array();
 $requestData= $_REQUEST;

 $count=mysqli_query($con, "SELECT * FROM employees");
 $totalData= $count->num_rows;
 $totalFiltered=$totalData;

 $json_data = array(
            "draw"            => intval( $requestData['draw'] ),   // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw.
            "recordsTotal"    => intval( $totalData ),  
            "recordsFiltered" => intval( $totalFiltered ), 
            "data"            => $data   // total data array
            );

 echo json_encode($json_data);
 ?>
 </script>
   <body>

 <?php
 $data=array();
 $requestData= $_REQUEST;
 $query=mysqli_query($con, "SELECT * FROM employees");
 $totalData= $count->num_rows;
 $totalFiltered=$totalData;

 if( !empty($requestData['search']['value']) ) {
    // if there is a search parameter
    $sql = "SELECT first_name, last_name, position, date, updated";
    $sql.=" FROM employees";
    $sql.=" WHERE first_name LIKE '".$requestData['search']['value']."%' ";
    // $requestData['search']['value'] contains search parameter
    $sql.=" OR last_name LIKE '".$requestData['search']['value']."%' ";
     $sql.=" OR position LIKE '".$requestData['search']['value']."%' ";
      $sql.=" OR date LIKE '".$requestData['search']['value']."%' ";
       $sql.=" OR updated LIKE '".$requestData['search']['value']."%' ";

    $query=mysqli_query($con, $sql);
    $totalFiltered = mysqli_num_rows($query); // when there is a search parameter then we have to modify total number filtered rows as per search result without limit in the query

    $sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]."   ".$requestData['order'][0]['dir']."   LIMIT ".$requestData['start']." ,".$requestData['length']."   "; // $requestData['order'][0]['column'] contains colmun index, $requestData['order'][0]['dir'] contains order such as asc/desc , $requestData['start'] contains start row number ,$requestData['length'] contains limit length.
    $query=mysqli_query($con, $sql); // again run query with limit

} else {   

    $sql = "SELECT first_name, last_name, position, date, updated";
    $sql.=" FROM employees";
    $sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]."   ".$requestData['order'][0]['dir']."   LIMIT ".$requestData['start']." ,".$requestData['length']."   ";
    $query=mysqli_query($con, $sql);

}

$data = array();
while( $row=mysqli_fetch_array($query) ) {  // preparing an array
    $nestedData=array();

    $nestedData[] = $row["titulo"];
    $nestedData[] = $row["descripcion"];

    $data[] = $nestedData;
}

 ?>
$(文档).ready(函数(){
var asc=真;
$('#示例')。数据表({
“处理”:对,
“服务器端”:正确,
“ajax”:{
“url”:“server.php”,
“类型”:“职位”,
},
columnDefs:[{
目标:-1,
defaultContent:“删除”
}],
行组:{
dataSrc:1
}
});
});
身份证件
名字
姓
位置
日期
更新
行动
Server.php

<?php
    $table = 'employees';
    $primaryKey = 'id'; // Table's primary key

    $columns = array(
        array( 'db' => 'id', 'dt' => 0 ),
        array( 'db' => 'first_name', 'dt' => 1 ),
        array( 'db' => 'last_name',  'dt' => 2 ),
        array( 'db' => 'position',   'dt' => 3 ),
        array( 'db' => 'date',     'dt' => 4 ),
         array( 'db' => 'updated',     'dt' => 5 ),
    );

    $sql_details = array(
        'user' => 'username',
        'pass' => 'password',
        'db'   => 'database',
        'host' => 'localhost'
    );

    require( 'ssp.class.php' );

    echo json_encode(
        SSP::simple( $_GET, $sql_details, $table, $primaryKey, $columns )
    );
    ?>

似乎没人知道。我在“draw”上找到了这个描述:

“”draw“=>intval($requestData['draw']),//对于客户端的每个请求/绘制,他们都会发送一个数字作为参数,当他们收到响应/数据时,他们会首先检查绘制数字,因此我们在draw中发送相同的数字

链接:

这是一张更好的照片。我想总比什么都没有好