duanping1632 2013-08-28 17:20
浏览 90
已采纳

将SQLite用于我的网站数据库时的实用性和安全性? [关闭]

I am building a website for the company I work for, for which the front-end has been done. Currently the site populates itself from information read off a JSON file.

I will be leaving this job soon, and want to leave the site so that other employees will be able to update it without needing to know how to read and write JSON data properly. So I am writing a VERY simple site to do the updates (list the projects currently on the live site, lets users add a project, delete a project or reorder projects.) The data is all text, and I am doing some basic sanitizing in JS before calling the server to write. What's more, I am using .htaccess to require employees to log in to even get to this part of the site.

So now I am to the point where I need an actually database to write to. As our website is run off of an OSX server, we already had SQLite3 installed. It seemed from what I read here on StackOverflow that SQLite works just fine as a live database, as long as I dont need UN/PW access, or the need to scale up to 100k+ hits. (We are a small company - we will be getting 2-3 hits a day).

I starting setting up a PHP page to connect to the database and write to it, and after a silent failure, realized that the .DB file needed RW access for group in order for the website to access it. This would mean a chmod to at least 444, if not 777, for the db and the directory holding it (I assume). I asked my boss, who handles server admin, about setting this up, and he said he was not comfortable doing this. And while I understand his concern, I am not sure what else I am supposed to do. Without RW access on the file, I don't know any other means to make this work.

So what are my options? Should I abandon SQLite and just install MySQL? And if I do stick with SQLite, what are best practices for security? Is there some accepted best way to set it up the batabase / encrypt data / hide the database?

Thanks!

  • 写回答

1条回答 默认 最新

  • doubi7306 2013-08-28 17:43
    关注

    What you may be confusing here is UNIX/Linux file permissions with web accessibility.

    In *NIX, every file belongs to an owner and a group. Every process on the machine, including the user on a terminal, is running under a user which belongs to a group (or groups). That is what file permissions are about. They control which process can access which files. The user may have direct permissions for a file (user permissions), indirect permissions through his group membership or, if nothing else, other permissions.

    This all has nothing to do with a web user. The web server is a process listening to incoming HTTP requests on port 80 (or elsewhere). It then decides how to respond to these requests. At no point does this kind of do-I-respond-or-don't-I have anything to do with file permissions. The web server has its own rules for which requests to allow and which to deny, which have nothing to do with file permissions.

    If the web server is trying to access some file on disk, then file permissions play a role. The web server is running as some user belonging to some group, typically www-data. That means the web server can read, write or execute files that it has permissions to. If the web server does not have read permissions for a file, it won't be able to serve it. But just because the web server has write permissions to a file does not mean in any way that a website visitor can write to that file in any way, because the web server won't let them. The web server serves web request, it doesn't offer direct file access to random users.

    The typical setup is that the web server is running as www-data. An incoming request causes the web server to start a PHP script, which also runs as child process with www-data permissions. That PHP process reads or writes files; it can only read and write files with the permissions of www-data and you control what the script reads or writes.

    If you want to use a SQLite database, something will have to have permissions to that file. It's true that you typically want to separate permissions as much as possible. But in this case you need to give the www-data user (or whatever your PHP is running as) permissions to that file. So what? That's not a security flaw per se. The worst thing that could happen is that an attacker who gets permissions of www-data will be able to write to the database. But before that he'll have to have circumvented a whole lot of other security mechanisms, so that should be the least of your worries.

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

报告相同问题?

悬赏问题

  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了