douyong5825 2012-02-16 02:02
浏览 67
已采纳

这是安全的吗?

Code first, then an explanation:

<?php
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"".$_POST['filename']."\"");
$key = md5(rand());
echo $key;
$key = str_repeat($key,ceil(strlen($_POST['data'])/32));
echo $_POST['data'] ^ $key;
?>

What this does is allow me to POST data through a form (dynamically generated) and have the posted data be downloaded as a file.

I'm using a very basic XOR encryption that puts the (fixed-length, 32-byte) key at that start of the file. The intention is not to secure the data, but rather to obfuscate it.

Having such a file means that potentially anyone could POST whatever data they wanted to it and it would be offered as a download to the user's computer, but I believe a combination of the user having to accept the download, and the data being passed through XOR with a one-time key, is enough to prevent malicious use.

Is there any reason why I should not use such a file? Are there better alternatives to what I'm doing? Is application/octet-stream the appropriate MIME-type?

  • 写回答

1条回答 默认 最新

  • doukesou4452 2012-02-16 02:06
    关注

    It is completely safe from user's perspective - because it makes no sense for user to harm itself and POST cannot be passed by potentially malicious url or redirect. And even if it could - there is just a script that returns a file to download. This cannot harm anyone by definition.

    But you should keep in mind that after you sent it to user - you can never trust the data in case that you accept the data to deobfuscate and use in some way.

    Is application/octet-stream the appropriate MIME-type

    As long as you return binary data - yes, it is appropriate

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况