dtmu88600 2016-06-09 04:42
浏览 63

是否只使用SESSION中的令牌进行jQuery post请求到php脚本安全验证?

In a nutshell, what I'm trying to do is to make a jQuery POST request from a clicked html element that has an encrypted data attribute uid and sending this encrypted data attribute uid through the jQuery POST request to a getData.php file which decrypts the uid and uses the decrypted uid to query from the database and return json encoded results.

Here is what the .html file would contain:

<div data-uid="YshZrKI4qWCHBUnX3vd/Aw==" class="request" style="border:5px solid black;">
    uid is encrypted with AES-128-CBC
</div>

This would be the jquery:

$('.request').on('click', function() {
        var UID=$(this).data('uid');
        $.post( "pull/data.php", { uid:UID}) // Maybe add a token?
          .done(function(request_data) {
            data = JSON.parse(request_data);
            alert(data);
          });
    });

pull/data.php would look something like this:

//some kind of verification here? 
if($_SESSION['User']['Token'] == SomeKindOfValidationFunc()) // Would this make it more secure?
    include_once '../databack.php';
    include_once '../keys/request.key.php'; // contains static key and iv
    $key = $evalrequest_key;
    $iv = $evalrequest_iv;

    $id = openssl_decrypt($_POST['uid'], 'AES-128-CBC', $key,0,$iv);
    $results = Get("SELECT * FROM tableX"); //just returns an associative array of results from db

    echo json_encode($results);

Is this technique safe?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!