安全地存储私有映像 [英] Securely storing private images

查看:184
本文介绍了安全地存储私有映像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要的,用于存储一个较大的(未知)私人图像仅由特定的用户访问量的安全的解决方案。这个问题是不是周围事物一样登录,会议或类似的东西 - 只周围的图像,并将它们存储

我将开始与解释什么,我想实现,然后去到的事情,我想这样做。

I'll start out with explaining what I am trying to achieve and then go on to things I've thought about doing.

专用图像只能由特定用户访问

一个在我的网站用户登录上传和查看提供和上传的图片由他/她。这些图像只应该用户可访问 - 因此需要登录。当被请求观看图像,渲染是由PHP脚本验证用户的权限,并从安全的目录带来实际的图像处理。

A user logs in to my site to upload and view images provided and uploaded by him/her. The images should only be accessible by that user - therefore a login is required. When a image is requested for viewing, the rendering is handled by a PHP-script validating the user's authority and bringing the actual image from the safe directory.

我知道,假设和思考的问题。

What I know, assume and think about.

索引图像,便于同治的

这被上传被索引在数据库中进行管理的每一个形象,即

Every image that gets uploaded is indexed in a database for management, i.e.

Title: "Me on a scooter"
User: {0E4A759A-CC31-4B0D-97E1-EEFB28F0BF86}
Filename: asuohLAFUUHJSFUhaSGFUOAHSGUA
Extension: .jpg

当用户想要观看图像时,服务器验证并检查是否该用户是的确图像的所有者。

When the user wants to view the image, the server validates and checks if the user is indeed the owner of the image.

保持公众远离图像

我读过一些文章解释说,这是很好的做法,以保持文档根目录以外的文件。虽然我理解这个概念,我不完全了解如何做到这一点的做法。我的假设:

I've read some articles explaining that it's good practice to keep files outside of the document root directory. Though I understand the concept, I don't fully understand how to do it in practice. My assumption:

/var/www/myFolder/ //here's where the html files are stored
/mySecureFolder/ //here's where the content are stored outside of the root, or on a higher level

所以,只要服务器应显示的图像看起来它在/ mySecureFolder /并检查文件,使得它为用户之前存在。

So whenever the server should display an image it looks for it in the /mySecureFolder/ and checks if the file exists before rendering it for the user.

假设#2

创建和放置一个.htaccess文件阻挡,但每个人都在本地主机的/ mySecureFolder /是我应该做的,让别人了。

Creating and placing an .htaccess file blocking everyone but localhost in the /mySecureFolder/ is what I should do to keep others out.

问题1 PHP的进程正在运行作为用户WWW的数据,它是安全,使/ mySecureFolder / WWW的数据所有者组?

Question #1 The PHP process is running as the user www-data, is it safe to make the owner group of /mySecureFolder/ www-data?

假设#3 - 文件模式

要允许没有,但一个特定的系统用户,我应该recursivly文件模式的文件夹0770,只允许所有者用户和所有者组的读,写和执行权限。

To allow none but one specific system user i should CHMOD the folder recursivly with 0770, allowing only the owner user and the owner group to read, write and execute permissions.

问题#2

时使用的.htaccess拒绝到放置安全的文件夹的根目录以外的任何人访问,但本地主机当量(在/ var / WWW / MyFolder的/)文件夹?

Is using .htaccess to deny access to everyone but localhost equivalent to placing the secure folder outside the root (/var/www/myFolder/) folder?

假设#4矫枉过正

加密存储在文件系统中的每个图像勉强,并且 - 如果目录权限设置是否正确 - 不需要

Encrypting every image stored on the filesystem is overdoing it and - if the directory permissions are set up correctly - unnecessary.

我的攻击情形只有外部的攻击,黑客无法访问服务器低谷SSH也不是通过实际是在服务器上。因此,可能的攻击是外部攻击来自我创造了code未来 - 就像针剂等

My attack scenario is only outer attacks, hackers cannot access the server trough SSH nor via physically being at the server. The possible attacks are therefore outer attacks coming from the code I created - like injections and so on.

我希望可能的答案可能会派上用场的未来bypassers,所以想AP preciate,如果你帮我走出格式化这个问题,以确保它是尽可能清晰。

推荐答案

最好的办法是将存储图像/ WWW之外 - 并让他们在自己的目录

The best way is to store the images outside of /www - and have them in their own directory.

然后使用的ReadFile()来'服务'的图像,授权用户。没有需要属性或使用htaccess的等等 - 因为它是www文件夹内,不能被除通过应用程序访问

Then use readfile() to 'serve' the images to the authorised user. No need to CHMOD or use htaccess etc - as it is outside the www folder and cannot be accessed except through your application.

像这样的工作:

function show_image($file_name= "")
{
    // Ensure no funny business names to prevent directory transversal etc.
    $file_name = str_replace ('..', '', $file_name);
    $file_name = str_replace ('/', '', $file_name);

    // now do the logic to check user is logged in - put your own code here
    if (LoggedInUserCanAccessThisFile())
    {
        // Serve file via readfile()
        // Images are stored in a specific user folder - so only the own user can get their own images
        readfile('../image_storage/' . getLoggedInUserID() . '/' . $file_name);
    }
}

您可以阅读更多有关的ReadFile()这里php.net

这篇关于安全地存储私有映像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆