简体   繁体   English

在HTTP_RAW_POST_DATA上进行输入验证

[英]input validation on HTTP_RAW_POST_DATA

I'm using jQuery webcam plugin from xarg.org, this plugin allow to use user webcam thanks to flash application and take snap. 我正在使用来自xarg.org的jQuery网络摄像头插件,该插件允许使用用户网络摄像头,这要归功于Flash应用程序并抓紧时间。

When taking a snap, image is sent to php script for saving image by HTTP_RAW_POST_DATA. 进行快照时,图像将通过HTTP_RAW_POST_DATA发送到php脚本以保存图像。 The author propose this script: 作者提出以下脚本:

<?php
$str = file_get_contents("php://input");
file_put_contents("/tmp/upload.jpg", pack("H*", $str));
?>

My problem is the input validation, I don't know how to test data from HTTP_RAW_POST_DATA. 我的问题是输入验证,我不知道如何测试HTTP_RAW_POST_DATA中的数据。

I add this test after the previous script: 我在上一个脚本之后添加此测试:

$imageOK=true;
$imagesize = getimagesize("views/img/order.jpg");
if(@is_array($imagesize)){
    if($imagesize[mime]!="" && $imagesize[mime]=="image/jpeg"){
        $imageOK=true;
    }
    else {
    $imageOK=false;
    }
} else {
    $imageOK=false;
}
if(!$imageOK)
    unlink("views/img/order.jpg");

Do you think it is secure? 您认为它安全吗? If not, which kind of test can I do? 如果没有,我可以做哪种测试?

Thanks 谢谢

You check the file type with getimagesize() , which is good and secure. 您可以使用getimagesize()检查文件类型,这是很好且安全的。

But I don't see on your code any validation of the file size . 但是我在您的代码上看不到文件大小的任何验证。

The golden rule is to never trust input from the client. 黄金法则是永远不要信任客户端的输入。 So you should check server-side the size of the file. 因此,您应该检查服务器端文件的大小。

You can check the Owasp website, which gives some good practices about file upload : https://www.owasp.org/index.php/Unrestricted_File_Upload 您可以访问Owasp网站,该网站提供了有关文件上传的一些良好做法: https ://www.owasp.org/index.php/Unrestricted_File_Upload

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM